saadeghi / daisyui

๐ŸŒผ ๐ŸŒผ ๐ŸŒผ ๐ŸŒผ ๐ŸŒผ โ€ƒThe most popular, free and open-source Tailwind CSS component library
https://daisyui.com
MIT License
34.24k stars 1.31k forks source link

bug: Theme toggle does not default to dark mode if the system/browser is already in dark mode #2847

Closed indcoder closed 9 months ago

indcoder commented 9 months ago

What version of daisyUI are you using?

4.6.0

Which browsers are you seeing the problem on?

Chrome, Edge

Reproduction URL

https://daisyui.com/components/theme-controller/

Describe your issue

We are using the theme controller to control between the light and dark theme

I noticed while the theme controller works as expected if the system/browser is in light mode. But if its not, the theme controller does not default to the dark mode.

image

Also when I change the value to dark when the browser is in dark mode by default the

image

I see the checked bool and value getting triggered.

image

But when I reverse the toggle back to light, it still remains dark even though css values seem to suggest the light theme needs to be in effect. Also tried with updating checkbox value to "light"

image
github-actions[bot] commented 9 months ago

Thank you @indcoder for reporting issues. It helps daisyUI a lot ๐Ÿ’š
I'll be working on issues one by one. I will help with this one as soon as a I find a solution.
In the meantime providing more details and reproduction links would be helpful.

saadeghi commented 9 months ago

Unchecked checkbox with theme-controller class does nothing.
Checked checkbox with theme-controller class applies the theme specified in value.
So theme-controller does not care about your system theme, and yes as you said, if the system theme is dark, it switches dark to dark.
This is not a bug. It's how it's expected to work logically if you think about it.

To overcome that, you can disable system dark mode using darkTheme: false config. This way, the unchecked checkbox will be light and checked will be dark.

Another thing you can do use radio inputs:
https://daisyui.com/components/theme-controller/#theme-controller-using-a-radio-input

Because a checkbox can only have 2 values. With radio buttons you can have 3 values or more (system / light / dark)

Let me know if you have a question.