Sub topic 10
Making State Changes Accessible
Assume you already know basic UI design, asynchronous data fetching, HTML, and TypeScript. This chapter focuses on making loading, empty, and error states perceivable and usable with screen readers, keyboard navigation, and other assistive technology.
A visual change is not automatically an accessible change. A spinner may be visible but silent. A red border may show an error but provide no useful message. When a screen changes state, users need to know:
- What changed.
- Which part of the interface changed.
- Whether they need to act.
- Where they should move next.
Announce important changes
A live region is an element whose text changes are announced by assistive technology. Use role="status" for information that can wait, such as “Loading projects…” or “Project saved.” Use role="alert" for an important error that needs immediate attention.
aria-live="polite" waits until the user pauses. This is usually the right setting for loading and success messages. An assertive announcement can interrupt the user's current task, so reserve it for urgent information.
<div role="status" aria-live="polite" id="project-status"></div>
<main aria-labelledby="page-title">
<h1 id="page-title">Projects</h1>
<ul id="project-list" aria-busy="true">
<li class="skeleton-row"></li>
<li class="skeleton-row"></li>
</ul>
<div id="project-error" role="alert" hidden>
Couldn't load projects. Check your connection and try again.
</div>
</main>The live region should exist before its content changes. If JavaScript creates the region only after an event, some screen readers may not detect the update reliably.
aria-busy="true" tells assistive technology that a region is still being updated. Set it to false when the content is ready. Do not leave it true after an error or successful response.
Manage focus when the context changes
Focus is the current keyboard position. A screen reader often follows focus, so focus management helps users understand major changes.
For a small update, keep focus where it is and announce the change. For a major context change, move focus deliberately. Examples include:
- Navigating to a new page in a single-page application.
- Opening a dialog.
- Showing a form error summary after submission.
- Replacing a route with an unrecoverable error screen.
A page-level change can move focus to the new page heading:
function focusPageHeading(): void {
const heading = document.querySelector<HTMLElement>("h1");
if (!heading) {
return;
}
heading.tabIndex = -1;
heading.focus();
}Do not move focus every time a list refreshes. Unexpected focus movement makes keyboard use difficult. Keep focus on the control that started the action unless the old control disappears or the user must address an error.
Make empty states understandable
An empty state is successful content with zero items. Announce the result in the page content, not only through a live region. The heading should identify what is empty, and the next action should be keyboard accessible.
For example, “No projects yet. Create your first project” explains both the result and the next step. “Nothing here” does neither.
An empty state caused by a filter needs different guidance: “No projects match these filters. Clear a filter or create a project.” This distinction matters because the recovery action depends on the cause.
Make errors perceivable and recoverable
An error message should be connected to the affected content and should explain a next action. Error text should not depend on color alone.
Use an alert for an important failure, but also place the message near the failed region. A retry button needs an accessible name that describes what it retries, such as “Try loading projects again.”
For form errors, place focus on an error summary or the first invalid field after submission. Include a text message next to the field and connect it with aria-describedby.
Trace a state change
A useful design review follows the same path for every state:
Test with a keyboard, a screen reader, zoom, and reduced-motion settings. Verify that focus remains visible, every state has a readable name, and recovery controls are reachable without a mouse.
Exercise
A list refreshes after the user selects a filter. Should the interface move focus to the list and announce every changed row?
Show answer
No. Keep focus on the filter control, mark the list busy while it updates, and politely announce a concise result such as “12 projects shown.” Move focus only if the previous focus target disappears or the user must address an error.