A sighted user sees the count change as they type, and notices "Saved" appear.
Without an announcement, a screen reader user typing in the text box may not
notice changes elsewhere. The count and the saved message need a way to be
discovered without moving focus.
Runs with Vite on your computer: unzip, then npm install and npm run dev.
src/liveLog.js stands in for a screen reader. It watches the page and logs
announced: followed by the text whenever a live region changes. Type in the
filter and press Save filter: the console stays empty, because nothing on
this page is a live region yet.
Live regions
A live region is an element whose changes a screen reader announces,
without moving focus there:
aria-live="polite" announces changes when the screen reader has finished
what it's saying.
role="status" is a ready-made polite live region, for status messages.
aria-live="assertive", or role="alert", interrupts. Use it only for urgent
problems, such as a failed save.
Add both attributes to the lab, then type st and press Save filter.
Check what you see
The console now logs a line for each change: announced: 11 topics after
s, announced: 3 topics after t, then announced: Saving… and
announced: Saved "st" as a favourite filter.
The logger is a rough model. If you have a real screen reader, such as
VoiceOver on a Mac or NVDA on Windows, try it too: it may merge or skip quick
changes. Your browser's developer tools also have an Accessibility pane,
which shows each element's role and whether it's live.
The region must already exist
Screen readers watch live regions for changes. A region that appears with
its text already in it is often not announced at all. So this doesn't work
reliably:
JSX
{status && <p role="status">{status}</p>}
Render the region always, empty when there's nothing to say, and change only
its text, as the lab does. The lab's logger behaves the same way: change the
status paragraph to the version above and save a filter, and Saving… is
never logged.
Don't overdo it
Announce what users need to know and can't otherwise find out: results counts,
saved or failed, errors after submitting. Announcing every keystroke's count is
borderline. Some apps wait until typing pauses, with a debounced value, before
updating the region.
Exercise
Announce only after a pause
Keep the visible count instant, but update the announced count only when
typing has stopped for 500 ms. The lab includes src/useDebouncedValue.js,
the hook from Intermediate Day 5: it returns its value only after the value has
stopped changing for the delay you give it.
Check it in the console: typing st quickly should log one announced: 3
topics, half a second after you stop, not one line per letter.
Runs with Vite on your computer: unzip, then npm install and npm run dev.
Hint 1: the idea
One number can't be both instant and delayed. So the page needs two copies of
the count: the visible one, which isn't live, and an announced one, which is a
live region fed by a value that waits for typing to pause. The announced copy
can be hidden from sight but must stay in the accessibility tree.
Hint 2: a first step
Remove aria-live from the visible count, and add a second paragraph with
aria-live="polite" that shows the same count. Type st: the console logs a
line per letter, so the new region works. Now change what that second
paragraph shows, using the hook in src/useDebouncedValue.js, and import it in
App.jsx.
Show one solution
JavaScript
const announced = useDebouncedValue(matches.length, 500);
Import it with import { useDebouncedValue } from "./useDebouncedValue.js";.
The visually hidden style
keeps the region out of sight but in the accessibility tree; display: none
would hide it from screen readers too.
Completion is saved in this browser only. It does not measure mastery.