[site] Replace theme menu with synced toggle - #1485
Conversation
|
A live preview of this PR will be available at the URL(s) below. https://pr1485-cbca93e---lit-dev-5ftespv5na-uc.a.run.app/ |
|
Updated all screenshot goldens from the macOS CI artifacts produced by Integration tests run 33547534756. The follow-up Integration tests run 33548989291 passed all 41 tests with no screenshot diffs. |
|
Fixed same-tab navigation resetting the theme in commit |
|
Removed the navigation icon flash in commit |
| const storeColorMode = (mode: ColorMode | undefined) => { | ||
| try { | ||
| if (mode) { | ||
| sessionStorage.setItem(COLOR_MODE_STORAGE_KEY, mode); |
There was a problem hiding this comment.
previously this was stored in local storage. with session storage the user's choice is lost when the tab is closed, though i suppose that is the only way to revert to "auto" with this new toggle.
i kind of think if the user did explicitly click the toggle to switch mode, we should persist that across sessions?
There was a problem hiding this comment.
This is following Lea Verou's latest blogpost which I really vibed with.
If the user really cares about a specific mode, they probably would change their OS to that mode. SessionStorage stores it for the current tab for fast loads (if overridden), and SharedWorker should sync it across tabs
There was a problem hiding this comment.
It looks like the current implementation violates this: https://lea.verou.me/blog/2026/dark-mode-toggles/#tri-state-toggles-are-implementation-driven-ui:~:text=When%20you%20press%20it%20for%20the%20first%20time%2C%20it%20toggles%20to%20the%20opposite%20of%20what%20you%E2%80%99re%20currently%20seeing%2C%20and%20stores%20the%20literal%20value%20(light%20or%20dark).%20The%20next%20time%20you%20press%20it%2C%20it%20toggles%20back%20to%20the%20system%20default%2C%20and%20removes%20the%20stored%20value.
Right now in the latest preview, with my system on light mode, opening the page there's no value stored. Clicking the toggle sets "dark". Clicking it again sets "light" where I would expect the value to be unset to revert to system setting.
I also don't see any rationale in the blog post that an override should only last the session. If the user chose to override, I think it should stay in localStorage to persist across sessions, as the first graphic in the blog post shows as well.
There was a problem hiding this comment.
fun post to read https://lea.verou.me/blog/2026/dark-mode-toggles/
There was a problem hiding this comment.
Additionally, if the state changes due to a change in system, it should reset the state to auto
Summary
SharedWorker, while resetting to the system preference after all tabs closelitdev-ripple-icon-buttonusage and fix disclosure state, accessible names, link semantics, and keyboard focus indicationTesting
npm run build -w lit-dev-contentnpm run build -w lit-dev-tests