Skip to content

Commit 009a67a

Browse files
authored
[material-ui][Drawer] Add dialog role and aria-modal for temporary variant (#46690)
1 parent 1f63b03 commit 009a67a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

packages/mui-material/src/Drawer/Drawer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ const Drawer = React.forwardRef(function Drawer(inProps, ref) {
287287
additionalProps: {
288288
elevation: variant === 'temporary' ? elevation : 0,
289289
square: true,
290+
...(variant === 'temporary' && {
291+
role: 'dialog',
292+
'aria-modal': 'true',
293+
}),
290294
},
291295
});
292296

packages/mui-material/src/Drawer/Drawer.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,44 @@ describe('<Drawer />', () => {
155155
});
156156
});
157157

158+
describe('accessibility', () => {
159+
it('should have role="dialog" and aria-modal="true" when variant is temporary', () => {
160+
render(
161+
<Drawer open variant="temporary">
162+
<div data-testid="child" />
163+
</Drawer>,
164+
);
165+
166+
const paper = document.querySelector(`.${classes.paper}`);
167+
expect(paper).to.have.attribute('role', 'dialog');
168+
expect(paper).to.have.attribute('aria-modal', 'true');
169+
});
170+
171+
it('should not have role="dialog" and aria-modal="true" when variant is permanent', () => {
172+
render(
173+
<Drawer variant="permanent">
174+
<div data-testid="child" />
175+
</Drawer>,
176+
);
177+
178+
const paper = document.querySelector(`.${classes.paper}`);
179+
expect(paper).not.to.have.attribute('role');
180+
expect(paper).not.to.have.attribute('aria-modal');
181+
});
182+
183+
it('should not have role="dialog" and aria-modal="true" when variant is persistent', () => {
184+
render(
185+
<Drawer variant="persistent">
186+
<div data-testid="child" />
187+
</Drawer>,
188+
);
189+
190+
const paper = document.querySelector(`.${classes.paper}`);
191+
expect(paper).not.to.have.attribute('role');
192+
expect(paper).not.to.have.attribute('aria-modal');
193+
});
194+
});
195+
158196
it('should set the custom className for Modal when variant is temporary', () => {
159197
render(
160198
<Drawer className="woofDrawer" open variant="temporary">

0 commit comments

Comments
 (0)