-
Notifications
You must be signed in to change notification settings - Fork 6k
Use announce function in live region #38084
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,24 +17,24 @@ class LiveRegion extends RoleManager { | |
| LiveRegion(SemanticsObject semanticsObject) | ||
| : super(Role.labelAndValue, semanticsObject); | ||
|
|
||
| String? lastAnnouncement; | ||
| String? _lastAnnouncement; | ||
|
|
||
| @override | ||
| void update() { | ||
| // Avoid announcing the same message over and over. | ||
| if (lastAnnouncement != semanticsObject.label) | ||
| if (_lastAnnouncement != semanticsObject.label) | ||
| { | ||
|
||
| lastAnnouncement = semanticsObject.label; | ||
| if (lastAnnouncement != null) { | ||
| _lastAnnouncement = semanticsObject.label; | ||
| if (_lastAnnouncement != null) { | ||
| accessibilityAnnouncements.announce( | ||
| lastAnnouncement! , Assertiveness.polite | ||
| _lastAnnouncement! , Assertiveness.polite | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void _cleanupDom() { | ||
| lastAnnouncement = null; | ||
| _lastAnnouncement = null; | ||
|
||
| } | ||
|
|
||
| @override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1744,7 +1744,7 @@ void _testImage() { | |
| } | ||
|
|
||
| void _testLiveRegion() { | ||
| test('renders a live region if there is a label', () async { | ||
| test('announces the label after an update', () async { | ||
| semantics() | ||
| ..debugOverrideTimestampFunction(() => _testTime) | ||
| ..semanticsEnabled = true; | ||
|
|
@@ -1759,14 +1759,11 @@ void _testLiveRegion() { | |
| ); | ||
| semantics().updateSemantics(builder.build()); | ||
|
|
||
| expectSemanticsTree(''' | ||
| <sem aria-label="This is a snackbar" aria-live="polite" style="$rootSemanticStyle"></sem> | ||
| '''); | ||
|
|
||
| expect(accessibilityAnnouncements.ariaLiveElementFor(Assertiveness.polite).text, 'This is a snackbar'); | ||
| semantics().semanticsEnabled = false; | ||
| }); | ||
|
|
||
| test('does not render a live region if there is no label', () async { | ||
| test('does not announce anything if there is no label', () async { | ||
| semantics() | ||
| ..debugOverrideTimestampFunction(() => _testTime) | ||
| ..semanticsEnabled = true; | ||
|
|
@@ -1780,9 +1777,7 @@ void _testLiveRegion() { | |
| ); | ||
| semantics().updateSemantics(builder.build()); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I'd add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! Done! |
||
| expectSemanticsTree(''' | ||
| <sem style="$rootSemanticStyle"></sem> | ||
| '''); | ||
| expect(accessibilityAnnouncements.ariaLiveElementFor(Assertiveness.polite).text, ''); | ||
|
|
||
| semantics().semanticsEnabled = false; | ||
| }); | ||
|
|
||
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.
I think the logic that protects us from announcing the same message again is missing a test. It can be tested by clearing the contents of
ariaLiveElementFor(Assertiveness.polite)after the first announcement, issuing an update with the same message, and verifying that the element remains empty.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.
Based on our conversation, I implemented a mock class for
AccessibilityAnnouncementsand added this test case.