Improved accessibility of sidebar navigation

This commit is contained in:
squidfunk
2023-01-08 12:48:46 +01:00
parent 5b35b7df57
commit f8f44f5837
7 changed files with 56 additions and 39 deletions

View File

@@ -43,6 +43,8 @@ import {
import { configuration, feature } from "./_"
import {
at,
getActiveElement,
getElement,
getOptionalElement,
requestJSON,
setLocation,
@@ -186,6 +188,18 @@ keyboard$
if (typeof next !== "undefined")
setLocation(next)
break
/* Expand navigation, see https://bit.ly/3ZjG5io */
case "Enter":
const active = getActiveElement()
if (active instanceof HTMLLabelElement) {
const id = `[id="${active.htmlFor}"]`
const input = getElement<HTMLInputElement>(id)
active.setAttribute(
"aria-expanded",
`${input.checked = !input.checked}`
)
}
}
})