← Back to React, page 4

react-0078 · Medium mid

How do you announce dynamic changes (saved, errors, loading) to screen reader users in a React app?

Use a live region: an element with role="status" (polite) or role="alert" (assertive) that is already in the DOM before its text changes. Updating the text inside it makes screen readers announce the message without moving focus. Render the region always, even when empty, because a region that appears together with its content is often not announced. Move focus instead for navigation changes and form error summaries.

Full answer

Sighted users see a toast or a changed label. Screen reader users only hear what the page announces, so dynamic updates need a live region.

role="status" is equivalent to aria-live="polite": the message waits until the user is idle. Use it for saved messages, search result counts and progress. role="alert" is assertive and interrupts, so reserve it for errors and urgent notices. aria-live and aria-atomic can be set directly for more control.

The key rule: the region must exist in the DOM before the content changes. Browsers register live regions when the page loads or the element is added empty. A region that is conditionally rendered together with its text may be skipped. So render <p role="status">{message}</p> always, and change only the children. The container can be visually hidden with a "visually-hidden" CSS class when the message is only for assistive technology.

In React: keep the message in state, update it after the event, and clear it later if needed. Avoid announcing the same message twice in a row, because identical text may not trigger an announcement. Do not make large regions live, because every change will be read out.

Other patterns. Form validation: on submit with errors, either move focus to an error summary (with role="alert" or tabIndex -1) or focus the first invalid field, and use aria-invalid and aria-describedby on inputs. Route changes: single-page apps do not reload, so move focus to the main heading or announce the new page title. Loading: announce "Loading results" and the final count, and use aria-busy on the updating area.

Test with a real screen reader. Automated tools cannot check announcement behaviour.

jsx
import { useState } from 'react';

export default function SaveButton() {
  const [status, setStatus] = useState('');
  const [error, setError] = useState('');

  function save(shouldFail) {
    setError('');
    setStatus('Saving...');
    setTimeout(() => {
      if (shouldFail) {
        setStatus('');
        setError('Could not save. Check your connection.');
      } else {
        setStatus('Saved at ' + new Date(Date.UTC(2026, 11, 4, 9, 30)).toISOString().slice(11, 16) + ' UTC');
      }
    }, 10);
  }

  return (
    <div>
      <button onClick={() => save(false)}>Save</button>
      <button onClick={() => save(true)}>Save (fails)</button>
      <p role="status">{status}</p>
      <p role="alert">{error}</p>
    </div>
  );
}

Both regions are always rendered and only their text changes, which is the important detail. The check pressed Save and the failing button. Rendered result: <div><button>Save</button><button>Save (fails)</button><p role="status"></p><p role="alert">Could not save. Check your connection.</p></div>

Key points

  • Use role="status" for polite messages and role="alert" for urgent ones.
  • Render the live region before changing its text.
  • Move focus for route changes and error summaries instead of using a live region only.
  • Keep regions small and avoid repeating identical messages.
  • Test with a screen reader because automation cannot verify speech.

Common mistakes

  • Rendering the live region together with its message, so it is not announced.
  • Using role="alert" for routine messages and interrupting the user.
  • Making a whole page section live.
  • Relying on color alone to show an error.
  • Assuming that automated tests prove announcements work.

Follow-ups

  • What is the difference between aria-live polite and assertive?
  • How do you manage focus after a route change in a single-page app?
  • How would you build an error summary for a long form?

Tips

  • State the "region must exist first" rule. It is the most useful fact.
  • Match politeness to urgency.
  • Mention testing with NVDA, VoiceOver or JAWS.