Skip to content

Commit

Permalink
Revert "Revert "fix(snack-bar): announcing same message twice to scre…
Browse files Browse the repository at this point in the history
…en readers" (#14494)"

This reverts commit e9466a4.
  • Loading branch information
vivian-hu-zz authored Dec 13, 2018
1 parent 53d2b58 commit fe58a16
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/lib/snack-bar/snack-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,16 @@ describe('MatSnackBar', () => {
}));


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

snackBar.open(simpleMessage);
snackBar.open(simpleMessage, undefined, {announcementMessage: simpleMessage});
viewContainerFixture.detectChanges();

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

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

it('should be able to specify a custom announcement message', fakeAsync(() => {
Expand Down
6 changes: 4 additions & 2 deletions src/lib/snack-bar/snack-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ export class MatSnackBar implements OnDestroy {
// override the data to pass in our own message and action.
_config.data = {message, action};

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

return this.openFromComponent(SimpleSnackBar, _config);
Expand Down

0 comments on commit fe58a16

Please sign in to comment.