Announcing dynamic updates
When content changes without a page load, sighted users see the new text appear. A screen reader user does not. Their reader only announces the part of the page they are focused on, so an update elsewhere passes them by. A live region tells assistive technology to announce changes to a region even when focus is somewhere else.
Give the region role="status" and change its contents:
const [message, setMessage] = useState('No items');
<button onClick={() => setMessage('1 item added')}>Add</button>
<p role="status">{message}</p>;
role="status" is a polite live region. The reader finishes its current
sentence, then announces the new text. That suits confirmations and counts. For
something urgent — an error, a session about to expire — use role="alert",
which interrupts and speaks at once.
Two things to remember. Render the live region once and change its text; a region that appears already populated is usually not announced. And keep the message short, because all of it is read aloud.
Your job is to announce a change through a polite live region.
Challenge
Adding an item changes the page, but nothing announces it. Export an App
component from App.jsx that renders an Add button and a status paragraph.
The paragraph starts as No items. After the button is clicked, it reads
1 item added, and it is a polite live region with role="status".
The Test clicks Add and expects the status region to read 1 item added. The
starter never updates, so the Test fails.