Skip to content

fix(material/dialog): dialog content not being read out by screen readers #14533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/material/dialog/dialog-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ export class MatDialogConfig<D = any> {
/** Aria label to assign to the dialog element. */
ariaLabel?: string | null = null;

// Note that this is disabled by default, because while the a11y recommendations are to focus
// the first focusable element, doing so prevents screen readers from reading out the
// rest of the dialog's content.
/** Whether the dialog should focus the first focusable element on open. */
autoFocus?: boolean = true;
autoFocus?: boolean = false;

/**
* Whether the dialog should restore focus to the
Expand Down
4 changes: 2 additions & 2 deletions src/material/dialog/dialog.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('dialog', () => {
await element(by.id('default')).click();

await waitForDialog();
await expectFocusOn('mat-dialog-container input');
await expectFocusOn('mat-dialog-container');
});

it('should restore focus to the element that opened the dialog', async () => {
Expand All @@ -76,7 +76,7 @@ describe('dialog', () => {
await element(by.id('default')).click();

await waitForDialog();
await pressKeys(Key.TAB, Key.TAB, Key.TAB);
await pressKeys(Key.TAB, Key.TAB, Key.TAB, Key.TAB);
await expectFocusOn('#close');
});

Expand Down
20 changes: 17 additions & 3 deletions src/material/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,18 +1081,32 @@ describe('MatDialog', () => {
beforeEach(() => document.body.appendChild(overlayContainerElement));
afterEach(() => document.body.removeChild(overlayContainerElement));

it('should focus the first tabbable element of the dialog on open', fakeAsync(() => {
it('should focus the dialog container by default', fakeAsync(() => {
dialog.open(PizzaMsg, {
viewContainerRef: testViewContainerRef
viewContainerRef: testViewContainerRef,
});

viewContainerFixture.detectChanges();
flushMicrotasks();

expect(document.activeElement!.tagName)
.toBe('INPUT', 'Expected first tabbable element (input) in the dialog to be focused.');
.toBe('MAT-DIALOG-CONTAINER', 'Expected dialog container to be focused.');
}));

it('should focus the first tabbable element of the dialog on open when autoFocus is enabled',
fakeAsync(() => {
dialog.open(PizzaMsg, {
viewContainerRef: testViewContainerRef,
autoFocus: true
});

viewContainerFixture.detectChanges();
flushMicrotasks();

expect(document.activeElement!.tagName)
.toBe('INPUT', 'Expected first tabbable element (input) in the dialog to be focused.');
}));

it('should allow disabling focus of the first tabbable element', fakeAsync(() => {
dialog.open(PizzaMsg, {
viewContainerRef: testViewContainerRef,
Expand Down