Improved accessibility of sidebar navigation

This commit is contained in:
squidfunk
2023-01-28 12:54:19 +01:00
parent ad6c47ddb6
commit 148c9fdba4
8 changed files with 46 additions and 30 deletions

View File

@@ -192,14 +192,8 @@ keyboard$
/* 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}`
)
}
if (active instanceof HTMLLabelElement)
active.click()
}
})

View File

@@ -28,9 +28,15 @@ import {
combineLatest,
defer,
distinctUntilChanged,
endWith,
finalize,
first,
from,
fromEvent,
ignoreElements,
map,
mergeMap,
takeUntil,
tap,
withLatestFrom
} from "rxjs"
@@ -153,6 +159,7 @@ export function mountSidebar(
const { y } = getElementOffset(inner)
return defer(() => {
const push$ = new Subject<Sidebar>()
const done$ = push$.pipe(ignoreElements(), endWith(true))
const next$ = push$
.pipe(
auditTime(0, animationFrameScheduler)
@@ -190,6 +197,22 @@ export function mountSidebar(
}
})
/* Handle accessibility for expandable items, see https://bit.ly/3jaod9p */
from(getElements<HTMLLabelElement>("label[tabindex]", el))
.pipe(
mergeMap(label => fromEvent(label, "click")
.pipe(
map(() => label),
takeUntil(done$)
)
)
)
.subscribe(label => {
const input = getElement<HTMLInputElement>(`[id="${label.htmlFor}"]`)
const nav = getElement(`[aria-labelledby="${label.id}"]`)
nav.setAttribute("aria-expanded", `${input.checked}`)
})
/* Create and return component */
return watchSidebar(el, options)
.pipe(