Skip to content

Commit 28743f1

Browse files
crisbetojelbourn
authored andcommitted
fix(select): add duration to live announcer message (#15655)
Sets a duration so that the live announcement message from `mat-select` is cleared after a while. Currently after the message is removed, the user can navigate to it using the arrow keys and moving focus all the way to the end of the page.
1 parent c039987 commit 28743f1

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/material/select/select.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ describe('MatSelect', () => {
378378

379379
dispatchKeyboardEvent(select, 'keydown', RIGHT_ARROW);
380380

381-
expect(liveAnnouncer.announce).toHaveBeenCalledWith('Steak');
381+
expect(liveAnnouncer.announce).toHaveBeenCalledWith('Steak', jasmine.any(Number));
382382

383383
flush();
384384
})));

src/material/select/select.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,9 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit,
734734
// Since the value has changed, we need to announce it ourselves.
735735
// @breaking-change 8.0.0 remove null check for _liveAnnouncer.
736736
if (this._liveAnnouncer && selectedOption && previouslySelectedOption !== selectedOption) {
737-
this._liveAnnouncer.announce((selectedOption as MatOption).viewValue);
737+
// We set a duration on the live announcement, because we want the live element to be
738+
// cleared after a while so that users can't navigate to it using the arrow keys.
739+
this._liveAnnouncer.announce((selectedOption as MatOption).viewValue, 10000);
738740
}
739741
}
740742
}

0 commit comments

Comments
 (0)