-
-
Notifications
You must be signed in to change notification settings - Fork 606
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve accessibility including voiceover
- Loading branch information
Showing
17 changed files
with
150 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
# Except these files & folders | ||
!/src | ||
!/public | ||
!/.github | ||
!tsconfig.json | ||
!astro.config.mjs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const primaryColorScheme = ""; // "light" | "dark" | ||
|
||
// Get theme data from local storage | ||
const currentTheme = localStorage.getItem("theme"); | ||
|
||
function getPreferTheme() { | ||
// return theme value in local storage if it is set | ||
if (currentTheme) return currentTheme; | ||
|
||
// return primary color scheme if it is set | ||
if (primaryColorScheme) return primaryColorScheme; | ||
|
||
// return user device's prefer color scheme | ||
return window.matchMedia("(prefers-color-scheme: dark)").matches | ||
? "dark" | ||
: "light"; | ||
} | ||
|
||
let themeValue = getPreferTheme(); | ||
|
||
function setPreference() { | ||
localStorage.setItem("theme", themeValue); | ||
reflectPreference(); | ||
} | ||
|
||
function reflectPreference() { | ||
document.firstElementChild.setAttribute("data-theme", themeValue); | ||
|
||
document.querySelector("#theme-btn")?.setAttribute("aria-label", themeValue); | ||
} | ||
|
||
// set early so no page flashes / CSS is made aware | ||
reflectPreference(); | ||
|
||
window.onload = () => { | ||
// set on load so screen readers can get the latest value on the button | ||
reflectPreference(); | ||
|
||
// now this script can find and listen for clicks on the control | ||
document.querySelector("#theme-btn").addEventListener("click", () => { | ||
themeValue = themeValue === "light" ? "dark" : "light"; | ||
setPreference(); | ||
}); | ||
}; | ||
|
||
// sync with system changes | ||
window | ||
.matchMedia("(prefers-color-scheme: dark)") | ||
.addEventListener("change", ({ matches: isDark }) => { | ||
themeValue = isDark ? "dark" : "light"; | ||
setPreference(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
--- | ||
export interface Props { | ||
noPadding?: boolean; | ||
ariaHidden?: boolean; | ||
} | ||
const { noPadding = false } = Astro.props; | ||
const { noPadding = false, ariaHidden = true } = Astro.props; | ||
--- | ||
|
||
<div class={`max-w-3xl mx-auto ${noPadding ? "px-0" : "px-4"}`}> | ||
<hr class="border-skin-line" /> | ||
<hr class="border-skin-line" aria-hidden={ariaHidden} /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.