️ fix: improve accessibility and i18n (#183)

This commit is contained in:
Óscar Fernández
2023-10-02 18:08:57 +02:00
committed by GitHub
parent 28fb52581f
commit 2c6ac293ad
25 changed files with 214 additions and 49 deletions

View File

@@ -8,6 +8,8 @@ let currentTheme = localStorage.getItem("theme") || document.documentElement.get
function setTheme(theme, saveToLocalStorage = false) {
document.documentElement.setAttribute("data-theme", theme);
currentTheme = theme;
let togglePressed = theme === "dark" ? "true" : "false";
themeSwitcher.setAttribute("aria-pressed", togglePressed);
if (saveToLocalStorage) {
localStorage.setItem("theme", theme);
@@ -29,6 +31,10 @@ function switchTheme() {
// Initialize the theme switcher button.
themeSwitcher.addEventListener("click", switchTheme, false);
themeSwitcher.setAttribute("role", "button");
themeSwitcher.setAttribute("aria-label", "Toggle dark mode");
let togglePressed = currentTheme === "dark" ? "true" : "false";
themeSwitcher.setAttribute("aria-pressed", togglePressed);
// Update the theme based on system preference if the user hasn't manually changed the theme.
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", e => {