Tailwind CSS

tailwind/sr-only-label

The only text of a button or link is never hidden with hidden; use sr-only (with md:not-sr-only to show it on wider screens).

poważnastatyczneWCAG 4.1.2 · Afe-tailwind

Dlaczego

hidden is display: none, which removes the text from the accessibility tree as well as from the screen. In <button><svg/><span class="hidden md:inline">Menu</span></button> the button has no name at all on phones: a screen reader announces only "button", and voice control users cannot say its name.

Poprawka

Use sr-only for text that should be read but not seen, and md:not-sr-only where it should also be seen on wider screens: <span class="sr-only md:not-sr-only">Menu</span>. Alternatively give the control aria-label. Mark the icon itself aria-hidden="true".

Przykłady

<!-- bad -->
<button type="button"><svg aria-hidden="true">…</svg><span class="hidden md:inline">Menu</span></button>
<!-- good -->
<button type="button"><svg aria-hidden="true">…</svg><span class="sr-only md:not-sr-only">Menu</span></button>

Źródła

Fakty

Identyfikator
tailwind/sr-only-label
Waga
poważna
Sprawdzanie
statyczne sprawdzane w kodzie źródłowym przez audit
Dotyczy plików
html angular vue svelte astro jsx
Tylko w projektach z
tailwind
WCAG 2.2
4.1.2, poziom A
Ten sam problem w
axe-core button-name, axe-core link-name
Uczy jej skill
fe-tailwind Tailwind CSS
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain tailwind/sr-only-label