-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat: aria live region for announcements #9653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mikeharv
wants to merge
4
commits into
RaspberryPiFoundation:v13
Choose a base branch
from
mikeharv:aria-live-region
base: v13
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Raspberry Pi Foundation | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import {assert} from '../../node_modules/chai/index.js'; | ||
| import { | ||
| sharedTestSetup, | ||
| sharedTestTeardown, | ||
| } from './test_helpers/setup_teardown.js'; | ||
|
|
||
| suite('Aria Live Region', function () { | ||
| setup(function () { | ||
| sharedTestSetup.call(this); | ||
| this.workspace = Blockly.inject('blocklyDiv', {}); | ||
| this.liveRegion = document.getElementById('blocklyAriaAnnounce'); | ||
| }); | ||
|
|
||
| teardown(function () { | ||
| sharedTestTeardown.call(this); | ||
| }); | ||
|
|
||
| test('live region is created', function () { | ||
| assert.isNotNull(this.liveRegion); | ||
| }); | ||
|
|
||
| test('live region has polite aria-live', function () { | ||
| assert.equal(this.liveRegion.getAttribute('aria-live'), 'polite'); | ||
| }); | ||
|
|
||
| test('live region has atomic true', function () { | ||
| assert.equal(this.liveRegion.getAttribute('aria-atomic'), 'true'); | ||
| }); | ||
|
|
||
| test('live region has status role by default', function () { | ||
| assert.equal(this.liveRegion.getAttribute('role'), 'status'); | ||
| }); | ||
|
|
||
| test('live region is visually hidden but not display none', function () { | ||
| const style = window.getComputedStyle(this.liveRegion); | ||
| assert.notEqual(style.display, 'none'); | ||
| }); | ||
|
|
||
| test('createLiveRegion only creates one region (singleton)', function () { | ||
| // Calling again should not create a duplicate. | ||
| Blockly.utils.aria.initializeGlobalAriaLiveRegion( | ||
| this.workspace.getInjectionDiv(), | ||
| ); | ||
|
|
||
| const regions = this.workspace | ||
| .getInjectionDiv() | ||
| .querySelectorAll('#blocklyAriaAnnounce'); | ||
|
|
||
| assert.equal(regions.length, 1); | ||
| }); | ||
|
|
||
| test('announcement is delayed', function () { | ||
| Blockly.utils.aria.announceDynamicAriaState('Hello world'); | ||
|
|
||
| assert.equal(this.liveRegion.textContent, ''); | ||
|
|
||
| // Advance past the delay in announceDynamicAriaState. | ||
| this.clock.tick(11); | ||
| assert.include(this.liveRegion.textContent, 'Hello world'); | ||
| }); | ||
|
|
||
| test('repeated announcements are unique', function () { | ||
| Blockly.utils.aria.announceDynamicAriaState('Block moved'); | ||
| this.clock.tick(11); | ||
|
|
||
| const first = this.liveRegion.textContent; | ||
|
|
||
| Blockly.utils.aria.announceDynamicAriaState('Block moved'); | ||
| this.clock.tick(11); | ||
|
|
||
| const second = this.liveRegion.textContent; | ||
|
|
||
| assert.notEqual(first, second); | ||
| }); | ||
|
|
||
| test('last write wins when called rapidly', function () { | ||
| Blockly.utils.aria.announceDynamicAriaState('First message'); | ||
| Blockly.utils.aria.announceDynamicAriaState('Second message'); | ||
| Blockly.utils.aria.announceDynamicAriaState('Final message'); | ||
|
|
||
| this.clock.tick(11); | ||
|
|
||
| assert.include(this.liveRegion.textContent, 'Final message'); | ||
| }); | ||
|
|
||
| test('assertive option sets aria-live assertive', function () { | ||
| Blockly.utils.aria.announceDynamicAriaState('Warning', { | ||
| assertiveness: Blockly.utils.aria.LiveRegionAssertiveness.ASSERTIVE, | ||
| role: null, | ||
| }); | ||
|
|
||
| this.clock.tick(11); | ||
|
|
||
| assert.equal(this.liveRegion.getAttribute('aria-live'), 'assertive'); | ||
| }); | ||
|
|
||
| test('role option updates role attribute', function () { | ||
| Blockly.utils.aria.announceDynamicAriaState('Alert message', { | ||
| assertiveness: Blockly.utils.aria.LiveRegionAssertiveness.POLITE, | ||
| role: Blockly.utils.aria.Role.GROUP, | ||
| }); | ||
|
|
||
| this.clock.tick(11); | ||
|
|
||
| assert.equal(this.liveRegion.getAttribute('role'), 'group'); | ||
| }); | ||
|
|
||
| test('role and text update after delay', function () { | ||
| // Initial announcement to establish baseline role + text. | ||
| Blockly.utils.aria.announceDynamicAriaState('Initial message', { | ||
| assertiveness: Blockly.utils.aria.LiveRegionAssertiveness.POLITE, | ||
| role: Blockly.utils.aria.Role.STATUS, | ||
| }); | ||
| this.clock.tick(11); | ||
|
|
||
| assert.equal(this.liveRegion.getAttribute('role'), 'status'); | ||
| const initialText = this.liveRegion.textContent; | ||
|
|
||
| // Now announce with different role. | ||
| Blockly.utils.aria.announceDynamicAriaState('New message', { | ||
| assertiveness: Blockly.utils.aria.LiveRegionAssertiveness.POLITE, | ||
| role: null, | ||
| }); | ||
|
|
||
| // Before delay: role and text should not have changed yet. | ||
| this.clock.tick(5); | ||
| assert.equal(this.liveRegion.getAttribute('role'), 'status'); | ||
| assert.equal(this.liveRegion.textContent, initialText); | ||
|
|
||
| // After delay: both should update. | ||
| this.clock.tick(6); | ||
| assert.isNull(this.liveRegion.getAttribute('role')); | ||
| assert.include(this.liveRegion.textContent, 'New message'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this & the other changes in this file: is it possible perhaps to adapt the API the one proposed in the WIP screen reader design document? Specifically this section:
https://docs.google.com/document/d/1-q0paWfV9qYWoZKWb9BpcfYOy3xYZtvcLyuuD61qHXw/edit?tab=t.0#bookmark=id.a3l9k4e1tah4
That was written after analyzing the approach taken in the experimental branch, considering micro:bit's changes, and other longer-term considerations. If there's an aspect of the design that doesn't work then it'd be great to discuss (e.g. via chat and/or comments directly on the doc) so that the doc and code end up being close to the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Ben. Thanks for the link and comments. I've pushed an update that attempts to better align to the document. PTAL and let me know what you think.