feat: aria live region for announcements#9653
feat: aria live region for announcements#9653mikeharv merged 6 commits intoRaspberryPiFoundation:v13from
Conversation
BenHenning
left a comment
There was a problem hiding this comment.
Thanks @mikeharv! Had some initial thoughts--PTAL.
Separately for testing, I think it would still be a good idea, if possible, to try and add at least some fundamental tests for the new announcement behavior. Some things which are hopefully testable and could be quite valuable to avoid downstream issues:
- The live region is
polite. - The live region is displayed (i.e. not
display: nonesince this will then be ignored by screen readers). - That subsequent announcements even with the same text are unique from the last (e.g. due to the additional non-spoken character being toggled).
- The general behavior of the region correctly announcing.
It would also be helpful to test that the region updates its role and value after a delay but I'm not sure how easy that one is to check. This directly fixes a somewhat tricky-to-debug issue that micro:bit found and fixed, so a regression test for it is definitely a nice-to-have (and not something I think we can assume works correctly just from other tested functionality that eventually uses dynamic announcements).
BenHenning
left a comment
There was a problem hiding this comment.
Thanks @mikeharv! Great tests and changes overall! I had a few suggestions, PTAL.
BenHenning
left a comment
There was a problem hiding this comment.
Thanks @mikeharv! Generally happy with this, just had one follow-up. Going ahead and approving to unblock you but feel free to assign back to me if you want me to look at any follow-up changes.
| * @param element DOM node to set role of. | ||
| * @param roleName Role name. | ||
| */ | ||
| export function setRole(element: Element, roleName: Role | null) { |
There was a problem hiding this comment.
This part actually seems correct and worth keeping (and also worth updating the JSDoc for the function). We do want an ability to clear the role, we just don't need to do it as part of the status stuff below.
There was a problem hiding this comment.
Thanks Ben! I re-added the ability to clear the role, along with a direct removeRole function, similar to Closure (https://google.github.io/closure-library/api/goog.a11y.aria.html)
This adds an aria live region for announcing updates on Blockly. This was partially backported out of the screen-reader branch.
The basics
API verified by testing announcement of toast changes via uncommitted code.
The details
Resolves #9632
Fixes
Proposed Changes
During
inject(), we will create a displayed-but-user-invisible<div/>with idblocklyAriaAnnouncewhich is configured as an aria live region with passive priority. Other parts of Blockly will be able to callannounceDynamicAriaStatewith text to add to this region to be read by assistive technologies. An asynchronous timeout is used to manage replacing outdated pending announcements with the latest update.Reason for Changes
This will give us a centralized place to announce dynamic state changes and information that cannot otherwise be conveyed.
Test Coverage
Added ARIA live region tests covering initialization, accessibility attributes, delayed announcements, repeated message handling, last-write-wins behavior, and delayed updates to role and assertiveness to prevent regressions.
Documentation
N/A
Additional Information