Open btmills opened 1 month ago
To resolve the issue with the ESLint documentation website's theme selector, follow these steps:
Add a new button for the "System" theme option in the theme-switcher HTML markup:
<button id="system-theme-toggle" data-theme="system">System</button>
Modify the themes.js
script to handle the "System" theme option:
data-theme
attribute from the document.documentElement
and clear the theme
item from localStorage
when the "System" theme is selected.enableToggle
and disableToggle
functions to manage the "System" theme state.Here is the updated code for themes.js
:
document.addEventListener('DOMContentLoaded', function() {
// ... existing code ...
var system_theme_toggle = document.getElementById('system-theme-toggle');
system_theme_toggle.addEventListener("click", function() {
document.documentElement.removeAttribute('data-theme');
window.localStorage.removeItem("theme");
disableToggle(light_theme_toggle);
disableToggle(dark_theme_toggle);
enableToggle(system_theme_toggle);
}, false);
// ... existing code ...
var enableToggle = function(btn) {
btn.setAttribute("aria-pressed", "true");
if (btn === system_theme_toggle) {
disableToggle(light_theme_toggle);
disableToggle(dark_theme_toggle);
}
}
var disableToggle = function(btn) {
btn.setAttribute("aria-pressed", "false");
if (btn !== system_theme_toggle && light_theme_toggle.getAttribute("aria-pressed") === "false" && dark_theme_toggle.getAttribute("aria-pressed") === "false") {
enableToggle(system_theme_toggle);
}
}
// ... existing code ...
}, false);
By implementing these changes, users will be able to select the "System" theme option, which will allow the website to automatically match the system's light or dark mode preference.
Docs page(s)
all of them
What documentation issue do you want to solve?
The ESLint docs currently default to the browser's
prefers-color-scheme
setting for light/dark mode by default. And they have a Light/Dark selector to let the user specify an override.But, there's no way to remove the override: i.e. go back to the default behavior of using the browser/system preference. This feels like a bug / missing feature to me: what if the user wants go back to the system preference?
I've hit this where I've needed to change the page temporarily, but subsequently wanted to go back to synced with the browser/system preferences.
What do you think is the correct solution?
A few UI options come to mind, in order of what I think is most intuitive & usable first:
The current selector, for reference:![Screenshot of the ESLint docs Light/Dark buttons, with light mode selected](https://github.com/eslint/eslint/assets/3335181/8cb3b56f-39c0-497b-a5ae-d9e53f1ed4dc)
Participation
Additional comments
Sibling issue to #18189.