Skip to content

Use prefers-color-scheme preference over localStorage color mode #787

@joe-bell

Description

@joe-bell

Describe the bug

When toggling between light/dark mode on a supoprted device (in this case iOS, or MacOS via Firefox), Theme-UI's color scheme does not update. Updating the app to reflect the user's color mode requires the localstorage to be deleted.

but may I add, setting up dark/light mode in it's current state has been an absolute breeze - thank you!

To Reproduce
Steps to reproduce the behavior:

  1. Follow steps outlined in https://theme-ui.com/color-modes/
  2. Clear local storage and refresh
  3. App should render with your system preferences
  4. Try toggling between light/dark mode in your system preferences and watch the behaviour of the app.

Expected behavior

As I've enabled useColorSchemeMediaQuery, I would expect the color modes to behave as a media query (in other words, on user-agent change - much like a breakpoint).

Screenshots

An example in Theme-UI: (using useColorSchemeMediaQuery)

Demo site toggling between dark and light mode on an iPhone

Examples of 'expected behaviour' in non-Theme-UI applications

Twitter toggling dark and light mode

DuckDuckGo

Additional context
Related issues: #367

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestreleasedThis issue/pull request has been released.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions