Skip to content

Commit 0852c88

Browse files
committed
fix(cdk/dialog): default aria-modal to false (#30411)
Having `aria-modal="true"` appears to hide other overlay-based components like `mat-select` from assistive technology. These changes set the default to `false` since the attribute is redundant anyway, because the dialog marks all outside content as `aria-hidden`. (cherry picked from commit c1ff40f)
1 parent b72838b commit 0852c88

File tree

6 files changed

+55
-11
lines changed

6 files changed

+55
-11
lines changed

src/cdk/dialog/dialog-config.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ export class DialogConfig<D = unknown, R = unknown, C extends BasePortalOutlet =
8787
/** Dialog label applied via `aria-label` */
8888
ariaLabel?: string | null = null;
8989

90-
/** Whether this is a modal dialog. Used to set the `aria-modal` attribute. */
91-
ariaModal?: boolean = true;
90+
/**
91+
* Whether this is a modal dialog. Used to set the `aria-modal` attribute. Off by default,
92+
* because it can interfere with other overlay-based components (e.g. `mat-select`) and because
93+
* it is redundant since the dialog marks all outside content as `aria-hidden` anyway.
94+
*/
95+
ariaModal?: boolean = false;
9296

9397
/**
9498
* Where the dialog should focus on open.

src/cdk/dialog/dialog.spec.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,18 @@ describe('Dialog', () => {
9494
viewContainerFixture.detectChanges();
9595
let dialogContainerElement = overlayContainerElement.querySelector('cdk-dialog-container')!;
9696
expect(dialogContainerElement.getAttribute('role')).toBe('dialog');
97-
expect(dialogContainerElement.getAttribute('aria-modal')).toBe('true');
97+
expect(dialogContainerElement.getAttribute('aria-modal')).toBe('false');
98+
});
99+
100+
it('should be able to set aria-modal', () => {
101+
dialog.open(PizzaMsg, {
102+
viewContainerRef: testViewContainerRef,
103+
ariaModal: true,
104+
});
105+
viewContainerFixture.detectChanges();
106+
107+
const container = overlayContainerElement.querySelector('cdk-dialog-container')!;
108+
expect(container.getAttribute('aria-modal')).toBe('true');
98109
});
99110

100111
it('should open a dialog with a template', () => {
@@ -117,7 +128,7 @@ describe('Dialog', () => {
117128

118129
let dialogContainerElement = overlayContainerElement.querySelector('cdk-dialog-container')!;
119130
expect(dialogContainerElement.getAttribute('role')).toBe('dialog');
120-
expect(dialogContainerElement.getAttribute('aria-modal')).toBe('true');
131+
expect(dialogContainerElement.getAttribute('aria-modal')).toBe('false');
121132

122133
dialogRef.close();
123134
});

src/material/bottom-sheet/bottom-sheet-config.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ export class MatBottomSheetConfig<D = any> {
4444
/** Aria label to assign to the bottom sheet element. */
4545
ariaLabel?: string | null = null;
4646

47-
/** Whether this is a modal bottom sheet. Used to set the `aria-modal` attribute. */
48-
ariaModal?: boolean = true;
47+
/**
48+
* Whether this is a modal dialog. Used to set the `aria-modal` attribute. Off by default,
49+
* because it can interfere with other overlay-based components (e.g. `mat-select`) and because
50+
* it is redundant since the dialog marks all outside content as `aria-hidden` anyway.
51+
*/
52+
ariaModal?: boolean = false;
4953

5054
/**
5155
* Whether the bottom sheet should close when the user goes backwards/forwards in history.

src/material/bottom-sheet/bottom-sheet.spec.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,17 @@ describe('MatBottomSheet', () => {
153153

154154
const containerElement = overlayContainerElement.querySelector('mat-bottom-sheet-container')!;
155155
expect(containerElement.getAttribute('role')).toBe('dialog');
156-
expect(containerElement.getAttribute('aria-modal')).toBe('true');
156+
expect(containerElement.getAttribute('aria-modal')).toBe('false');
157+
});
158+
159+
it('should be able to set aria-modal', () => {
160+
bottomSheet.open(PizzaMsg, {
161+
ariaModal: true,
162+
});
163+
viewContainerFixture.detectChanges();
164+
165+
const container = overlayContainerElement.querySelector('mat-bottom-sheet-container')!;
166+
expect(container.getAttribute('aria-modal')).toBe('true');
157167
});
158168

159169
it('should close a bottom sheet via the escape key', fakeAsync(() => {

src/material/dialog/dialog-config.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ export class MatDialogConfig<D = any> {
104104
/** Aria label to assign to the dialog element. */
105105
ariaLabel?: string | null = null;
106106

107-
/** Whether this is a modal dialog. Used to set the `aria-modal` attribute. */
108-
ariaModal?: boolean = true;
107+
/**
108+
* Whether this is a modal dialog. Used to set the `aria-modal` attribute. Off by default,
109+
* because it can interfere with other overlay-based components (e.g. `mat-select`) and because
110+
* it is redundant since the dialog marks all outside content as `aria-hidden` anyway.
111+
*/
112+
ariaModal?: boolean = false;
109113

110114
/**
111115
* Where the dialog should focus on open.

src/material/dialog/dialog.spec.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,18 @@ describe('MatDialog', () => {
112112
viewContainerFixture.detectChanges();
113113
let dialogContainerElement = overlayContainerElement.querySelector('mat-dialog-container')!;
114114
expect(dialogContainerElement.getAttribute('role')).toBe('dialog');
115-
expect(dialogContainerElement.getAttribute('aria-modal')).toBe('true');
115+
expect(dialogContainerElement.getAttribute('aria-modal')).toBe('false');
116+
});
117+
118+
it('should be able to set aria-modal', () => {
119+
dialog.open(PizzaMsg, {
120+
viewContainerRef: testViewContainerRef,
121+
ariaModal: true,
122+
});
123+
viewContainerFixture.detectChanges();
124+
125+
const container = overlayContainerElement.querySelector('mat-dialog-container')!;
126+
expect(container.getAttribute('aria-modal')).toBe('true');
116127
});
117128

118129
it('should open a dialog with a template', () => {
@@ -134,7 +145,7 @@ describe('MatDialog', () => {
134145

135146
let dialogContainerElement = overlayContainerElement.querySelector('mat-dialog-container')!;
136147
expect(dialogContainerElement.getAttribute('role')).toBe('dialog');
137-
expect(dialogContainerElement.getAttribute('aria-modal')).toBe('true');
148+
expect(dialogContainerElement.getAttribute('aria-modal')).toBe('false');
138149

139150
dialogRef.close();
140151
});

0 commit comments

Comments
 (0)