Dostępność

a11y/menu-not-for-site-nav

Site navigation is a nav with a list of links and disclosure buttons, not role="menu" or role="menubar".

umiarkowanastatyczneWCAG 4.1.2 · Afe-a11y-menus

Dlaczego

role="menu" tells screen readers to expect an application menu: arrow keys move, Tab leaves, items are commands. Website navigation built that way usually lacks the arrow-key code, and it hides that the items are links, so people cannot list or open them as links. The APG has a menubar example for navigation, but recommends the disclosure pattern as the simpler fit for most sites.

Poprawka

Use <nav aria-label="Main"> with <ul> and <a href>; mark the current page with aria-current="page"; open sub-lists with a <button aria-expanded> (the disclosure pattern). Keep role="menu" for command menus in applications (row actions, editor toolbars) and implement its keys.

Przykłady

<!-- bad -->
<nav><ul role="menubar"><li role="none"><a role="menuitem" href="/">Home</a></li></ul></nav>
<!-- good -->
<nav aria-label="Main"><ul><li><a href="/" aria-current="page">Home</a></li></ul></nav>

Źródła

Fakty

Identyfikator
a11y/menu-not-for-site-nav
Waga
umiarkowana
Sprawdzanie
statyczne sprawdzane w kodzie źródłowym przez audit
Dotyczy plików
html angular vue svelte astro jsx
WCAG 2.2
4.1.2, poziom A
Uczy jej skill
fe-a11y-menus Navigation, disclosures and menus
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain a11y/menu-not-for-site-nav