Dostępność
a11y/control-name
Every button and link has an accessible name; icon-only controls get visually hidden text or aria-label.
krytycznastatyczneWCAG 4.1.2, 2.4.4 · Afe-a11y-aria
Dlaczego
A button with only an icon is announced as "button" and nothing else. Screen reader and voice control users cannot tell what it does or say its name to activate it.
Poprawka
Prefer visible text. For an icon-only control, add text that is hidden visually but read (<span class="sr-only">Close</span>) or aria-label="Close", and mark the icon aria-hidden="true". A linked image names the link through its alt. Use the same word people see in tooltips and elsewhere on the site.
Przykłady
<!-- bad -->
<button type="button"><svg aria-hidden="true">…</svg></button>
<!-- good -->
<button type="button" aria-label="Close"><svg aria-hidden="true">…</svg></button>
<button type="button"><svg aria-hidden="true">…</svg><span class="sr-only">Close</span></button>Źródła
Fakty
- Identyfikator
a11y/control-name- Waga
- krytyczna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
htmlangularvuesvelteastrojsx- WCAG 2.2
- 4.1.2, 2.4.4, poziom A
- Ten sam problem w
- axe-core
button-name, axe-corelink-name, axe-coreinput-button-name, Lighthousebutton-name, Lighthouselink-name - Uczy jej skill
fe-a11y-ariaARIA, names and live regions- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain a11y/control-name