Skip to content

Popover API: announce toast notifications to screen readers - #403

Merged
chrisdavidmills merged 2 commits into
mdn:mainfrom
IvanGiovany:popover-toast-live-region
Oct 14, 2026
Merged

chrisdavidmills merged 2 commits into
mdn:mainfrom
IvanGiovany:popover-toast-live-region

Conversation

@IvanGiovany

@IvanGiovany IvanGiovany commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the toast example part of mdn/content#35811.

The toast popover demo didn’t announce notifications to screen readers. This adds a persistent, visually hidden output>live region, based on the status-message popover example in the HTML spec. Each time a toast is shown, its message is copied into the , so it’s announced.

The visible toasts are unchanged and stay outside the live region. An earlier attempt placed the toasts inside the output, but Chrome re-read every visible toast on each change (even with aria-atomic="false"), so the live region holds only the latest message instead.

Notes

The is cleared and then set after 100ms, so repeated identical messages are still announced.
It’s hidden with a visually-hidden pattern rather than display: none, so screen readers can still access it.
If toasts are triggered faster than the screen reader can speak, a newer message may interrupt an earlier one. This seems acceptable for toast notifications.

Testing (NVDA [version], Windows)

Original demo: toasts not announced
This change, Chrome [version]: each toast announced once, including repeated identical messages; nothing announced when toasts expire
This change, Firefox [version]: same as Chrome

The fixed version:
https://github.com/user-attachments/assets/35cff46c-f4dd-4d69-899d-feeb7299dc59

Add a persistent, visually hidden <output> element to the toast
popovers example. Each time a toast is shown, its message is copied
into the <output>, which is a live region, so screen readers announce
it. The text is cleared and then set after a short delay so that the
same message twice in a row is still announced.

The toasts themselves stay outside the <output>: when several toasts
were placed inside it, Chrome re-announced every visible toast on
each change, including removals, even with aria-atomic="false".

Based on the status message example in the HTML specification.
Update the README accessibility note to describe the new behavior.

Refs mdn/content#35811
@IvanGiovany
IvanGiovany force-pushed the popover-toast-live-region branch from 3c91214 to b37d64b Compare October 13, 2026 13:38

@chrisdavidmills chrisdavidmills left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IvanGiovany good work; I've tested it, and it fixes the problem. I also checked the MDN content repo, and it doesn't mention it specifically, so no synchronization changes are needed.

I just had a couple of minor comments.

Comment thread popover-api/toast-popovers/index.js Outdated
}

function announce(msg) {
// The <output> element is a live region, so screen readers announce changes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the comment to mention that it is implicitly a live region due to it having an implicit ARIA status role.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

Comment thread popover-api/README.md Outdated
@@ -18,6 +18,7 @@ These examples show how the Popover API behaves; they are not complete accessibl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this line? The toast example is now accessible. Maybe something like:

Some of these examples are not fully accessible; they were written to show how the Popover API behaves. The following notes comment on their accessibility status.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

@chrisdavidmills
chrisdavidmills removed the request for review from dipikabh October 14, 2026 08:50

@chrisdavidmills chrisdavidmills left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looking good. Thanks for the improvement, @IvanGiovany!

@chrisdavidmills
chrisdavidmills merged commit 93d7d40 into mdn:main Oct 14, 2026
1 check passed
@IvanGiovany
IvanGiovany deleted the popover-toast-live-region branch October 15, 2026 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants