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

Data-theme global setting not work #52

Open
valokammi opened this issue Jan 25, 2025 · 5 comments
Open

Data-theme global setting not work #52

valokammi opened this issue Jan 25, 2025 · 5 comments

Comments

@valokammi
Copy link

valokammi commented Jan 25, 2025

I have global setting <html lang="fi" data-theme="dark"> in template. Page renders out light theme. Theme switcher works like it should at least when selecting dark theme, not tested OS theme setting.
EDIT: Turned off Theme swicther (html and js) and theme is now dark! So this might be js issue in minimal-theme-switcher.js?

Expected Behavior

Whole page except elements that are point to light theme should be dark.

Environment

Windows 10, Laragon (devserver), Modx, Firefox.

@Yohn
Copy link
Owner

Yohn commented Jan 26, 2025

Nice find, does this also happen with the newer toggle switch light / dark mode SwitchColorMode.js?

@valokammi
Copy link
Author

valokammi commented Jan 26, 2025

Tested with old and new js.
Old don't respect global dark mode but switcher works.
New respects global dark mode but switcher not work (does nothing).

Edit: Firefox console got error (js loaded ok):
Theme switcher toggle not found SwitchColorMode.js:20:12 init https://pico.local/assets/templates/pico/js/SwitchColorMode.js:20 <anonymous> https://pico.local/assets/templates/pico/js/SwitchColorMode.js:76

@Yohn
Copy link
Owner

Yohn commented Jan 26, 2025

make sure you have the following where you'd like the switch to be:

<label>
	<input aria-label="Toggle Light or Dark Mode" name="color-mode-toggle" value="1" type="checkbox" role="switch">
</label>

@valokammi
Copy link
Author

valokammi commented Jan 27, 2025

Tried that. Not respect global theme setting and nothing happens in selector. No errors in console!
When I reload page I can see flash of dark mode in menu buttons.
Here's html code in my top bar:

<!--PICO Top bar Hamburger NAV ALKAA-->
<nav class="container-fluid" role="navigation" data-position="end" data-breakpoint="xl">
<!--PICO Top bar Hamburger Menu ALKAA-->
<!--PICO Top bar Hamburger Menu OUTER-->
<input type="checkbox" id="hamburger">
<label for="hamburger" style="font-size: calc(var(--pico-font-size) * 2);" aria-label="Menu" aria-controls="top-nav">&equiv;</label>
<ul id="top-nav" role="list">
<!--PICO Top bar Hamburger Menu row-->
<li role="listitem"><a href="[/](view-source:https://pico.local/)" >Pico CSS</a></li>
<!--PICO Top bar Hamburger Menu row-->
<li role="listitem">
<details class="dropdown">
<summary>Alasivu 1</summary>
<ul>
<li><a href="[alasivu-1/](view-source:https://pico.local/alasivu-1/)" >Alasivu 1</a>
<!--PICO Top bar Hamburger Menu INNER -->
<!--PICO Top bar Hamburger Menu INNER row-->
<li><a href="[alasivu-1/alasivu-1-2.html](view-source:https://pico.local/alasivu-1/alasivu-1-2.html)" >Alasivu 1-2</a></li>
</ul>
</details>
</li>
<!--PICO Top bar Hamburger Menu row-->
<li role="listitem">
<details class="dropdown">
<summary>Alasivu 2</summary>
<ul>
<li><a href="[alasivu-2/](view-source:https://pico.local/alasivu-2/)" >Alasivu 2</a>
<!--PICO Top bar Hamburger Menu INNER -->
<!--PICO Top bar Hamburger Menu INNER row-->
<li><a href="[alasivu-2/alasivu-2-1.html](view-source:https://pico.local/alasivu-2/alasivu-2-1.html)" >Alasivu 2-1</a></li>
</ul>
</details>
</li>
</ul>
<!--PICO Top bar Hamburger Menu LOPPUU-->
<!--PICO Top bar Search and Theme switch ALKAA-->
<label>
	<input aria-label="Toggle Light or Dark Mode" name="color-mode-toggle" value="1" type="checkbox" role="switch">
</label>
<ul>
<details class="dropdown">
<summary>Teema</summary>
<ul dir="rtl">
<li><a href="[#](view-source:https://pico.local/#)" data-theme-switcher="auto">Järjestelmän</a></li>
<li><a href="[#](view-source:https://pico.local/#)" data-theme-switcher="light">Vaalea</a></li>
<li><a href="[#](view-source:https://pico.local/#)" data-theme-switcher="dark">Tumma</a></li>
</ul>
</details>
<li>
<form role="search" action="[hakutulokset.html](view-source:https://pico.local/hakutulokset.html)" method="get">
  <input name="search" type="search" value="" placeholder="Hae">
  <input type="hidden" name="id" value="12">
  <input type="submit" value="Hae">
</form>
</li>
<li>
</ul>
<!--PICO Top bar Search and Theme switch LOPPUU-->
</nav>
<!--PICO Top bar Hamburger NAV LOPPUU-->

@valokammi
Copy link
Author

valokammi commented Jan 28, 2025

I got switcher working when I commented out that original drop down switcher. Find it out from Preview page source code.
But <html lang="fi" data-theme="dark"> not taking over page. No errors in console.
Edit: Switching OS to dark mode page turns dark mode too and vice versa. Have to clear browser cookie and page data to make this happen.

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

No branches or pull requests

2 participants