Dostępność
a11y/status-message-live
Messages that appear without moving focus (saved, results, errors, progress) are announced through a live region.
poważnaręczneWCAG 4.1.3 · AAfe-a11y-aria
Dlaczego
"Added to cart", "12 results" or "Upload failed" shown on screen is silent for a screen reader user unless it is in a live region. They act again, or never learn it failed.
Poprawka
Render an empty live region with the page (<div role="status">, polite) and put the text into it when the event happens; use role="alert" only for urgent errors. Do not mount the region and its text at the same moment: many screen readers announce only changes to a region that already existed.
Przykłady
<!-- good: present from the start, filled later -->
<p role="status" id="cart-status"></p>
<script type="module">
document.querySelector('#cart-status').textContent = 'Added to cart'
</script>Źródła
Fakty
- Identyfikator
a11y/status-message-live- Waga
- poważna
- Sprawdzanie
- ręczne ocenia człowiek; raport podaje to jako listę kontrolną
- Dotyczy plików
page- WCAG 2.2
- 4.1.3, poziom AA
- 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/status-message-live