fix(snackbar): set aria role based on if announcement message is provided (#13993)

This commit is contained in:
Joey Perrott
2018-11-07 10:21:41 -08:00
committed by vivian-hu
parent 81f8fb9582
commit 69ffd3306e
2 changed files with 22 additions and 8 deletions
+4 -4
View File
@@ -80,12 +80,12 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy
// Based on the ARIA spec, `alert` and `status` roles have an
// implicit `assertive` and `polite` politeness respectively.
if (snackBarConfig.politeness === 'assertive') {
if (snackBarConfig.politeness === 'assertive' && !snackBarConfig.announcementMessage) {
this._role = 'alert';
} else if (snackBarConfig.politeness === 'polite') {
this._role = 'status';
} else {
} else if (snackBarConfig.politeness === 'off') {
this._role = null;
} else {
this._role = 'status';
}
}
+18 -4
View File
@@ -67,8 +67,11 @@ describe('MatSnackBar', () => {
testViewContainerRef = viewContainerFixture.componentInstance.childViewContainer;
});
it('should have the role of `alert` with an `assertive` politeness', () => {
snackBar.open(simpleMessage, simpleActionLabel, {politeness: 'assertive'});
it('should have the role of `alert` with an `assertive` politeness if no announcement message ' +
'is provided', () => {
snackBar.openFromComponent(BurritosNotification,
{announcementMessage: '', politeness: 'assertive'});
viewContainerFixture.detectChanges();
const containerElement = overlayContainerElement.querySelector('snack-bar-container')!;
@@ -76,8 +79,19 @@ describe('MatSnackBar', () => {
.toBe('alert', 'Expected snack bar container to have role="alert"');
});
it('should have the role of `status` with an `assertive` politeness if an announcement message ' +
'is provided', () => {
snackBar.openFromComponent(BurritosNotification,
{announcementMessage: 'Yay Burritos', politeness: 'assertive'});
viewContainerFixture.detectChanges();
const containerElement = overlayContainerElement.querySelector('snack-bar-container')!;
expect(containerElement.getAttribute('role'))
.toBe('status', 'Expected snack bar container to have role="status"');
});
it('should have the role of `status` with a `polite` politeness', () => {
snackBar.open(simpleMessage, simpleActionLabel, {politeness: 'polite'});
snackBar.openFromComponent(BurritosNotification, {politeness: 'polite'});
viewContainerFixture.detectChanges();
const containerElement = overlayContainerElement.querySelector('snack-bar-container')!;
@@ -86,7 +100,7 @@ describe('MatSnackBar', () => {
});
it('should remove the role if the politeness is turned off', () => {
snackBar.open(simpleMessage, simpleActionLabel, {politeness: 'off'});
snackBar.openFromComponent(BurritosNotification, {politeness: 'off'});
viewContainerFixture.detectChanges();
const containerElement = overlayContainerElement.querySelector('snack-bar-container')!;