Dostępność
a11y/dialog-native
Build dialogs on the native <dialog> element opened with showModal() rather than a div with role="dialog".
drobnastatyczneWCAG 2.4.3, 4.1.2 · Afe-a11y-dialog
Dlaczego
A div dialog needs a hand-written focus trap, Escape handling, a way to hide the rest of the page from screen readers, and focus return. Each is a common source of bugs. <dialog> with showModal() does all of it and is Baseline widely available.
Poprawka
Render <dialog>, open it with dialog.showModal() (modal) or dialog.show() (non-modal), close it with dialog.close() or a <form method="dialog">, and style the overlay with ::backdrop. Keep a component library's dialog if the project uses one; check it renders <dialog> or implements the APG pattern.
Przykłady
<!-- bad -->
<div class="modal" role="dialog" aria-modal="true">…</div>
<!-- good -->
<dialog aria-labelledby="t"><h2 id="t">Newsletter</h2>…</dialog>
<script type="module">document.querySelector('dialog').showModal()</script>Źródła
Fakty
- Identyfikator
a11y/dialog-native- Waga
- drobna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
htmlangularvuesvelteastrojsx- WCAG 2.2
- 2.4.3, 4.1.2, poziom A
- Uczy jej skill
fe-a11y-dialogDialogs and modals- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain a11y/dialog-native