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

Apart from `light` and `dark`, add a `system` option

Open filiptronicek opened this issue 4 years ago • 9 comments

Is there any way (currently) or are there any plans on adding a system theme option that would just reflect the system and not override it? Or do I have to somehow make a custom one that clears the localStorage?

filiptronicek avatar Mar 04 '21 19:03 filiptronicek

If you never touch the toggle, it uses what the system says.

tomayac avatar Mar 05 '21 14:03 tomayac

@tomayac yes, I'm aware of that, but if I (as a random user) once accidentally touch the toggle, I can never go back (I have no idea how to clear local storage). Is that supposed to work like that? I think there could be a better solution.

filiptronicek avatar Mar 05 '21 15:03 filiptronicek

If the toggle doesn't have the permanent attribute, the site will reset to the system default.

Let's assume the system preference is light mode.

<dark-mode-toggle>:

  • Toggle dark mode.
  • Reload.
  • Mode is light again.

<dark-mode-toggle permanent>:

  • Toggle dark mode.
  • Reload.
  • Mode is dark again.

tomayac avatar Mar 05 '21 16:03 tomayac

(It's up to the site owner to choose if they set the permanent attribute. Personally, I do on my blog.)

tomayac avatar Mar 05 '21 16:03 tomayac

this is just bad UX. interacting with UI that cannot be undone, and practically speaking, is not recoverable for users, is bad design. a pretty fundamental key UI principle is that actions be easy reversible which this violates.

it's not like Google doesn't know how to write this behavior. some of its properties have a tristate theme selector.

vapier avatar Jan 13 '24 07:01 vapier

I changed my mind and now do think we should have at least an option to have a three-way toggle. Is anyone on this thread happy to work on a PR that adds such a feature?

tomayac avatar Jan 15 '24 09:01 tomayac

Functionality-wise, the "system" option would just need to delete the localStorage entry. The actual work would more need to focus on how to expose this UI wise. Some of the properties need rethinking, and the HTML structure, too. The appearance toggle means there's just one visible thing to click at a time that cycles through the possible states, and the switch means all possible states are visible at the same time and clickable.

tomayac avatar Jan 15 '24 09:01 tomayac

for me, the most time consuming part is the graphics, not the underlying logic. do we have an icon ready-to-go here ?

vapier avatar Jan 15 '24 22:01 vapier

I have seen sites use a slash icon like this.

tomayac avatar Jan 15 '24 22:01 tomayac