Dostępność

a11y/accordion-header

Each accordion header is a button with aria-expanded inside a heading of the right level; or use details and summary.

umiarkowanaręczneWCAG 1.3.1, 4.1.2 · Afe-a11y-tabs-accordion

Dlaczego

Clickable div headers cannot be reached with the keyboard, and without a heading around them screen reader users cannot jump between sections; without aria-expanded they cannot tell which section is open.

Poprawka

Simplest: <details name="faq"><summary>Question</summary>…</details> (a shared name keeps one open at a time). Custom: <h3><button type="button" aria-expanded="false" aria-controls="panel-1">Question</button></h3> and a panel with id="panel-1" that is hidden when closed. Add role="region" with aria-labelledby to panels only when there are few of them.

Przykłady

<!-- bad -->
<div class="accordion-header" onclick="toggle(1)">Shipping</div>
<!-- good -->
<h3><button type="button" aria-expanded="false" aria-controls="ship">Shipping</button></h3>
<div id="ship" hidden>…</div>

Źródła

Fakty

Identyfikator
a11y/accordion-header
Waga
umiarkowana
Sprawdzanie
ręczne ocenia człowiek; raport podaje to jako listę kontrolną
Dotyczy plików
html angular vue svelte astro jsx
WCAG 2.2
1.3.1, 4.1.2, poziom A
Uczy jej skill
fe-a11y-tabs-accordion Tabs and accordions
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain a11y/accordion-header