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

[Bug]: Changing Theme Switch is broken #498

Open
3 tasks done
JonathanWoollett-Light opened this issue Aug 31, 2024 · 2 comments
Open
3 tasks done

[Bug]: Changing Theme Switch is broken #498

JonathanWoollett-Light opened this issue Aug 31, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@JonathanWoollett-Light
Copy link

Before submitting...

Context

I recently attempted to add a theme switch to my webpage (JonathanWoollett-Light/cv@1e93235). I copied the code from https://materializeweb.com/themes.html and the element from the page.

It functions like the theme switch on https://materializeweb.com/themes.html except that the page theme doesn't change.

Current Behavior

The icon changes and the correct case occurs but the theme isn't changed.

Expected behavior

The page theme should be flipped between light and dark.

Possible Solutions or Causes

No response

Steps to reproduce

Open https://github.com/JonathanWoollett-Light/cv/blob/1e9323509877f1644fdba3fa83cc6bc0bf39282d/index.html in a webbrowser and click the theme switch icon.

It looks like:

Screenshot from 2024-08-31 13-29-44

Your Environment

  • Version used: 2.1.0
  • Browser Name and version: chrome
  • Operating System and version (desktop or mobile): ubuntu
  • Additional information you want to tell us:
@JonathanWoollett-Light JonathanWoollett-Light added the bug Something isn't working label Aug 31, 2024
@OlivierMadant
Copy link

Hello Jonathan,

If I try to run in the console from your website (https://jonathanwoollett-light.github.io/cv/) document.documentElement.setAttribute('theme', 'dark');
then the theme is switching in dark mode.

If I run document.documentElement.removeAttribute('theme'); then the theme is switching back in light mode.

So the theme change seems to work properly...

I hope this comment helps you.

Olivier

@JonathanWoollett-Light
Copy link
Author

JonathanWoollett-Light commented Sep 1, 2024

It seems to not work when my device theme is darkmode but does work when in lightmode.

I think the example assumes the device theme is lightmode so that when document.documentElement.removeAttribute('theme'); is run it switches to darkmode.

But when the device theme is darkmode when you run document.documentElement.removeAttribute('theme'); the site will remain dark.

A fix would be changing document.documentElement.removeAttribute('theme'); to document.documentElement.setAttribute('theme','light');, possibly in the future it could be extended with a 3rd state that passthroughs the theme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants