Dostępność
a11y/focus-route-change
After a client-side route change, focus moves to the new page's heading or main region and the new title is announced.
umiarkowanaręczneWCAG 2.4.3, 4.1.3 · Afe-a11y-keyboard
Dlaczego
In a single-page app the browser does not reload, so focus stays on the link that was clicked (or falls to <body>) and a screen reader says nothing. The person does not know the page changed.
Poprawka
Use the framework's announcer where it exists (Next.js and SvelteKit announce route changes; Nuxt has <NuxtRouteAnnouncer>). Then move focus: after navigation, focus the new page's <h1 tabindex="-1"> or <main tabindex="-1">. Keep each route's <title> unique, because announcers read it.
Przykłady
// good (Angular): focus the main heading after navigation
router.events.pipe(filter((e) => e instanceof NavigationEnd)).subscribe(() => {
document.querySelector('main h1')?.focus()
})Źródła
Fakty
- Identyfikator
a11y/focus-route-change- Waga
- umiarkowana
- Sprawdzanie
- ręczne ocenia człowiek; raport podaje to jako listę kontrolną
- Dotyczy plików
page- WCAG 2.2
- 2.4.3, 4.1.3, poziom A
- Uczy jej skill
fe-a11y-keyboardKeyboard access and focus- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain a11y/focus-route-change