dark-mode-switch icon indicating copy to clipboard operation
dark-mode-switch copied to clipboard

How to set dark mode as default

Open MG32Codes opened this issue 5 years ago • 7 comments

As the title says.

MG32Codes avatar Nov 11 '20 05:11 MG32Codes

Good question! You could set all the CSS as dark by default, and have the switch 'on' by default. If a user swicthes to 'off' you could load a light-mode CSS instead. It should be quite straight forward, though I may add a separate demo for that at some point.

coliff avatar Nov 11 '20 09:11 coliff

Alright, thanks!

MG32Codes avatar Nov 12 '20 00:11 MG32Codes

I think just add the data-theme="dark" to the <body> element. It will set the dark theme as default.

ardianta avatar Jan 14 '21 15:01 ardianta

I think to add the data-theme attribute would not be enough. truly the CSS would show the page with dark style, but the switch would appear off. The initTheme-method needs then to be extended to check if the attribute is already set. Currently only localStorage is checked. But I don´t know yet, if this would be the best solution. Indeed it would be useful to avoid some flickering or flashing when opening the page, while loading, instead of waiting for JS to be loaded and executed (like issue #22 )

crazychatting avatar Mar 15 '21 00:03 crazychatting

I think just add the data-theme="dark" to the <body> element. It will set the dark theme as default.

but there is a problem with the toggle if we make it like that

doniwirawan avatar Jul 24 '21 05:07 doniwirawan

I think just add the data-theme="dark" to the <body> element. It will set the dark theme as default.

but there is a problem with the toggle if we make it like that

Yes, the switch button will not updated.

I created custom script to handle it. See my changes: https://github.com/ardianta/dark-mode-switch/commit/9fad4b93e68d588559cfc898c0411b6665e063aa?branch=9fad4b93e68d588559cfc898c0411b6665e063aa&diff=split

ardianta avatar Jul 24 '21 09:07 ardianta

thanks mas

doniwirawan avatar Jul 24 '21 11:07 doniwirawan