Skip to content

Commit c9b30af

Browse files
authored
Revert "fix(snack-bar): announcing same message twice to screen readers (#13298)"
This reverts commit 3fb4b23.
1 parent 80c299f commit c9b30af

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/lib/snack-bar/snack-bar.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,18 @@ describe('MatSnackBar', () => {
186186
}));
187187

188188

189-
it('should clear the announcement message if it is the same as main message', fakeAsync(() => {
189+
it('should default to the passed message for the announcement message', fakeAsync(() => {
190190
spyOn(liveAnnouncer, 'announce');
191191

192-
snackBar.open(simpleMessage, undefined, {announcementMessage: simpleMessage});
192+
snackBar.open(simpleMessage);
193193
viewContainerFixture.detectChanges();
194194

195195
expect(overlayContainerElement.childElementCount)
196196
.toBe(1, 'Expected the overlay with the default announcement message to be added');
197197

198-
expect(liveAnnouncer.announce).not.toHaveBeenCalled();
198+
// Expect the live announcer to have been called with the display message and some
199+
// string for the politeness. We do not want to test for the default politeness here.
200+
expect(liveAnnouncer.announce).toHaveBeenCalledWith(simpleMessage, jasmine.any(String));
199201
}));
200202

201203
it('should be able to specify a custom announcement message', fakeAsync(() => {

src/lib/snack-bar/snack-bar.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,8 @@ export class MatSnackBar implements OnDestroy {
114114
// override the data to pass in our own message and action.
115115
_config.data = {message, action};
116116

117-
// Since the snack bar has `role="alert"`, we don't
118-
// want to announce the same message twice.
119-
if (_config.announcementMessage === message) {
120-
_config.announcementMessage = undefined;
117+
if (!_config.announcementMessage) {
118+
_config.announcementMessage = message;
121119
}
122120

123121
return this.openFromComponent(SimpleSnackBar, _config);

0 commit comments

Comments
 (0)