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

Toggle dark mode when prefers-color-scheme changes #642

Merged

Conversation

gabe565
Copy link
Contributor

@gabe565 gabe565 commented May 10, 2023

Description

Currently, if the prefers-color-scheme media query changes (for example, due to scheduled dark mode), the theme does not update until Homer is refreshed. This PR adds an event listener that toggles the mode dynamically. The dynamic change will not occur if the current mode has been overridden via the navbar toggle.

Examples

Current behavior

before-pr.mov

After this PR

after-pr3.mov

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I've read & comply with the contributing guidelines
  • I have tested my code for new features & regressions on both mobile & desktop devices, using the latest version of major browsers.
  • I have made corresponding changes to the documentation (README.md).
  • I've checked my modifications for any breaking changes, especially in the config.yml file

@netlify
Copy link

netlify bot commented May 10, 2023

Deploy Preview for homer-demo-content ready!

Name Link
🔨 Latest commit 92e9fba
🔍 Latest deploy log https://app.netlify.com/sites/homer-demo-content/deploys/645b4a0feff41f0008b7054f
😎 Deploy Preview https://deploy-preview-642--homer-demo-content.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@gabe565 gabe565 changed the title Watch prefers-color-scheme and toggle dark mode when it changes Toggle dark mode when prefers-color-scheme changes May 10, 2023
@gabe565 gabe565 force-pushed the watch-preferred-color-scheme branch from 9efdcd6 to 426c853 Compare May 10, 2023 07:36
@gabe565 gabe565 force-pushed the watch-preferred-color-scheme branch from 426c853 to 92e9fba Compare May 10, 2023 07:38
Copy link
Owner

@bastienwirtz bastienwirtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition @gabe565 !
Looks good to me, Thanks!

@bastienwirtz bastienwirtz merged commit 6cfa164 into bastienwirtz:main May 13, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants