Skip to content

Commit

Permalink
fix(dialog): add config option for aria-describedby (#5365)
Browse files Browse the repository at this point in the history
Adds an option to the dialog config that allows for the `aria-describedby` to be set on the dialog container.
  • Loading branch information
crisbeto authored and mmalerba committed Jul 7, 2017
1 parent 6b4f9c8 commit 68241a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/lib/dialog/dialog-config.ts
Expand Up @@ -63,5 +63,8 @@ export class MdDialogConfig {
/** Layout direction for the dialog's content. */
direction?: Direction = 'ltr';

/** ID of the element that describes the dialog. */
ariaDescribedBy?: string | null = null;

// TODO(jelbourn): add configuration for lifecycle hooks, ARIA labelling.
}
1 change: 1 addition & 0 deletions src/lib/dialog/dialog-container.ts
Expand Up @@ -67,6 +67,7 @@ export function throwMdDialogContentAlreadyAttachedError() {
'class': 'mat-dialog-container',
'[attr.role]': '_config?.role',
'[attr.aria-labelledby]': '_ariaLabelledBy',
'[attr.aria-describedby]': '_config?.ariaDescribedBy || null',
'[@slideDialog]': '_state',
'(@slideDialog.done)': '_onAnimationDone($event)',
},
Expand Down
11 changes: 10 additions & 1 deletion src/lib/dialog/dialog.spec.ts
Expand Up @@ -117,6 +117,15 @@ describe('MdDialog', () => {
expect(dialogContainerElement.getAttribute('role')).toBe('alertdialog');
});

it('should apply the specified `aria-describedby`', () => {
dialog.open(PizzaMsg, { ariaDescribedBy: 'description-element' });

viewContainerFixture.detectChanges();

let dialogContainerElement = overlayContainerElement.querySelector('md-dialog-container')!;
expect(dialogContainerElement.getAttribute('aria-describedby')).toBe('description-element');
});

it('should close a dialog and get back a result', async(() => {
let dialogRef = dialog.open(PizzaMsg, { viewContainerRef: testViewContainerRef });
let afterCloseCallback = jasmine.createSpy('afterClose callback');
Expand Down Expand Up @@ -666,7 +675,7 @@ describe('MdDialog', () => {
});
}));

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

Expand Down

0 comments on commit 68241a8

Please sign in to comment.