Skip to content

Commit 68241a8

Browse files
crisbetommalerba
authored andcommitted
fix(dialog): add config option for aria-describedby (#5365)
Adds an option to the dialog config that allows for the `aria-describedby` to be set on the dialog container.
1 parent 6b4f9c8 commit 68241a8

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/lib/dialog/dialog-config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,8 @@ export class MdDialogConfig {
6363
/** Layout direction for the dialog's content. */
6464
direction?: Direction = 'ltr';
6565

66+
/** ID of the element that describes the dialog. */
67+
ariaDescribedBy?: string | null = null;
68+
6669
// TODO(jelbourn): add configuration for lifecycle hooks, ARIA labelling.
6770
}

src/lib/dialog/dialog-container.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export function throwMdDialogContentAlreadyAttachedError() {
6767
'class': 'mat-dialog-container',
6868
'[attr.role]': '_config?.role',
6969
'[attr.aria-labelledby]': '_ariaLabelledBy',
70+
'[attr.aria-describedby]': '_config?.ariaDescribedBy || null',
7071
'[@slideDialog]': '_state',
7172
'(@slideDialog.done)': '_onAnimationDone($event)',
7273
},

src/lib/dialog/dialog.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ describe('MdDialog', () => {
117117
expect(dialogContainerElement.getAttribute('role')).toBe('alertdialog');
118118
});
119119

120+
it('should apply the specified `aria-describedby`', () => {
121+
dialog.open(PizzaMsg, { ariaDescribedBy: 'description-element' });
122+
123+
viewContainerFixture.detectChanges();
124+
125+
let dialogContainerElement = overlayContainerElement.querySelector('md-dialog-container')!;
126+
expect(dialogContainerElement.getAttribute('aria-describedby')).toBe('description-element');
127+
});
128+
120129
it('should close a dialog and get back a result', async(() => {
121130
let dialogRef = dialog.open(PizzaMsg, { viewContainerRef: testViewContainerRef });
122131
let afterCloseCallback = jasmine.createSpy('afterClose callback');
@@ -666,7 +675,7 @@ describe('MdDialog', () => {
666675
});
667676
}));
668677

669-
it('should set the aria-labelled by attribute to the id of the title', async(() => {
678+
it('should set the aria-labelledby attribute to the id of the title', async(() => {
670679
let title = overlayContainerElement.querySelector('[md-dialog-title]')!;
671680
let container = overlayContainerElement.querySelector('md-dialog-container')!;
672681

0 commit comments

Comments
 (0)