🌐 fix(theme-switcher): properly translate aria-label (#192)
Co-authored-by: Tim Böttcher <tim.boettcher2@rwth-aachen.de> Co-authored-by: welpo <welpo@users.noreply.github.com>
This commit is contained in:
parent
ab38f8434c
commit
2eaee6557c
@ -32,7 +32,6 @@ function switchTheme() {
|
|||||||
// Initialize the theme switcher button.
|
// Initialize the theme switcher button.
|
||||||
themeSwitcher.addEventListener("click", switchTheme, false);
|
themeSwitcher.addEventListener("click", switchTheme, false);
|
||||||
themeSwitcher.setAttribute("role", "button");
|
themeSwitcher.setAttribute("role", "button");
|
||||||
themeSwitcher.setAttribute("aria-label", "Toggle dark mode");
|
|
||||||
let togglePressed = currentTheme === "dark" ? "true" : "false";
|
let togglePressed = currentTheme === "dark" ? "true" : "false";
|
||||||
themeSwitcher.setAttribute("aria-pressed", togglePressed);
|
themeSwitcher.setAttribute("aria-pressed", togglePressed);
|
||||||
|
|
||||||
|
2
static/js/themeSwitcher.min.js
vendored
2
static/js/themeSwitcher.min.js
vendored
@ -1 +1 @@
|
|||||||
const themeSwitcher=document.querySelector(".theme-switcher");let currentTheme=localStorage.getItem("theme")||document.documentElement.getAttribute("data-theme");function setTheme(e,t=!1){document.documentElement.setAttribute("data-theme",e);var r="dark"===(currentTheme=e)?"true":"false",r=(themeSwitcher.setAttribute("aria-pressed",r),t&&localStorage.setItem("theme",e),new CustomEvent("themeChanged",{detail:{theme:e}}));window.dispatchEvent(r)}function switchTheme(){setTheme("dark"===currentTheme?"light":"dark",!0)}themeSwitcher.addEventListener("click",switchTheme,!1),themeSwitcher.setAttribute("role","button"),themeSwitcher.setAttribute("aria-label","Toggle dark mode");let togglePressed="dark"===currentTheme?"true":"false";themeSwitcher.setAttribute("aria-pressed",togglePressed),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{setTheme(e.matches?"dark":"light")});
|
const themeSwitcher=document.querySelector(".theme-switcher");let currentTheme=localStorage.getItem("theme")||document.documentElement.getAttribute("data-theme");function setTheme(e,t=!1){document.documentElement.setAttribute("data-theme",e),currentTheme=e;let r="dark"===e?"true":"false";themeSwitcher.setAttribute("aria-pressed",r),t&&localStorage.setItem("theme",e);const h=new CustomEvent("themeChanged",{detail:{theme:e}});window.dispatchEvent(h)}function switchTheme(){setTheme("dark"===currentTheme?"light":"dark",!0)}themeSwitcher.addEventListener("click",switchTheme,!1),themeSwitcher.setAttribute("role","button");let togglePressed="dark"===currentTheme?"true":"false";themeSwitcher.setAttribute("aria-pressed",togglePressed),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",(e=>{setTheme(e.matches?"dark":"light")}));
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
{%- set combined_mode_str = dark_str ~ "/" ~ light_str -%}
|
{%- set combined_mode_str = dark_str ~ "/" ~ light_str -%}
|
||||||
{%- set title_label = toggle_str | replace(from="$MODE", to=combined_mode_str) -%}
|
{%- set title_label = toggle_str | replace(from="$MODE", to=combined_mode_str) -%}
|
||||||
{%- set aria_label = 'Toggle ' ~ dark_str ~ ' mode' -%}
|
{%- set aria_label = toggle_str | replace(from="$MODE", to=dark_str) -%}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
title="{{ title_label }}"
|
title="{{ title_label }}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user