Skip to content

docs: Detect initial prefers-color-scheme value for mode localStorage #1001

@kylejrp

Description

@kylejrp

This is really a nitpick and not something too important to fix.

After having the docs site open all day, I just noticed it had a theme switcher. I'm rocking prefers-color-scheme: dark and it didn't detect it automatically. Any chance you'd consider adding a JavaScript prefers-color-scheme: dark and/or prefers-color-scheme: light and set the mode localStorage value appropriately (only if it's not already set)? 😄

https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/prefers-color-scheme

Something like:

if (localStorage.getItem('mode') === null) {
  if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
    localStorage.setItem('mode', 'dark');
  } else if (window.matchMedia('(prefers-color-scheme: light)').matches) {
    localStorage.setItem('mode', 'light');
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions