Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto darkmode does not work #403

Closed
MG-5 opened this issue Nov 5, 2023 · 2 comments · Fixed by #405 or #406
Closed

Auto darkmode does not work #403

MG-5 opened this issue Nov 5, 2023 · 2 comments · Fixed by #405 or #406
Assignees
Labels

Comments

@MG-5
Copy link
Contributor

MG-5 commented Nov 5, 2023

Describe the bug
The auto darkmode does not get the system darkmode, its always light.

To Reproduce
Steps to reproduce the behavior:

  1. Set system/browser theme to dark.
  2. If neccessary, clear browser session cache
  3. Open website
  4. See light site

Expected behavior
System dark mode leads to dark website

Additional context
I already fixed the problem in my case.

Line 38-40 in dark-mode.js

browserPrefersDark.addEventListener('change', () => {
if (browserPrefersDark.matches) sessionStorage.setItem('theme', 'dark')
});

creates an event handler, which is not triggered at the begin, so few lines later the session storage is always set to light cause of undefined sessionPrefers

setMode(sessionPrefers ? sessionPrefers : 'light')

You can fix the issue by adding the line

if (browserPrefersDark.matches) sessionStorage.setItem('theme', 'dark'); 

before the event handler. (like here)

(I could have created a PR with the fix myself, but I couldn't get gulp to work for generating main.min.js a folder above it.)

@MG-5 MG-5 added the bug label Nov 5, 2023
@sylhare
Copy link
Owner

sylhare commented Nov 6, 2023

Thanks for your input! Would you want to make a PR for it? (Since you already fixed it)

@MG-5
Copy link
Contributor Author

MG-5 commented Nov 6, 2023

If you have no problem, that I would edit the main.min.js manually? ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants