Dostępność
a11y/focus-visible
Never remove the focus outline without drawing a visible replacement for keyboard focus.
poważnastatyczneWCAG 2.4.7 · AAfe-a11y-keyboard
Dlaczego
Keyboard users see where they are only through the focus indicator. outline: none on :focus with nothing in its place leaves them lost on the page.
Poprawka
Style :focus-visible instead of removing focus styles: button:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }. If the design needs no ring for mouse clicks, :focus:not(:focus-visible) { outline: none; } is acceptable. With Tailwind, pair outline-none with a focus-visible:ring-* or focus-visible:outline-* class.
Przykłady
/* bad */
button:focus { outline: none; }
/* good */
button:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }Źródła
Fakty
- Identyfikator
a11y/focus-visible- Waga
- poważna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
cssscsslesshtmlangularvuesvelteastrojsx- WCAG 2.2
- 2.4.7, poziom AA
- 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-visible