Skip to content

Commit 54376f4

Browse files
Add dialog role to Popover (#1420)
Co-authored-by: Mayank <[email protected]>
1 parent 243e1b0 commit 54376f4

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

.changeset/odd-bugs-mate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@stratakit/mui": patch
3+
---
4+
5+
Add `role="dialog"` to `Popover`'s `paper` slot.

apps/website/src/content/docs/components/mui/Popover.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,15 @@ links:
77
---
88

99
::example{src="mui/Popover.default"}
10+
11+
## StrataKit MUI modifications
12+
13+
- Added [`role="dialog"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/dialog_role) to the `paper` slot.
14+
15+
## ✅ Do
16+
17+
- [Label](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/dialog_role#labeling) the **Popover's** `paper` slot using an `aria-labelledby` attribute pointing to a heading inside the popover or the trigger element's `id`.
18+
19+
## 🚫 Don't
20+
21+
- Don't forget to provide an accessible [label](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/dialog_role#labeling)

examples/mui/Popover.default.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,18 @@ export default () => {
1515
);
1616
const [open, setOpen] = React.useState(false);
1717
const buttonId = React.useId();
18-
const dialogId = React.useId();
1918
return (
2019
<>
2120
<Button
2221
id={buttonId}
2322
aria-haspopup="dialog"
24-
aria-controls={dialogId}
2523
aria-expanded={open}
2624
onClick={() => setOpen(true)}
2725
ref={setAnchorEl}
2826
>
2927
Open popover
3028
</Button>
3129
<Popover
32-
id={dialogId}
33-
role="dialog"
34-
aria-labelledby={buttonId}
3530
open={open}
3631
anchorEl={anchorEl}
3732
onClose={() => setOpen(false)}
@@ -42,6 +37,9 @@ export default () => {
4237
slotProps={{
4338
paper: {
4439
className: styles.popover,
40+
// note that the paper slot gets role="dialog" from the theme, so labelling by the button
41+
// ensures that the dialog is labeled by the button text
42+
"aria-labelledby": buttonId,
4543
},
4644
}}
4745
>

packages/mui/src/~createTheme.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,12 @@ function createTheme() {
363363
},
364364
},
365365
MuiPaper: { defaultProps: { component: Role.div } },
366-
MuiPopover: { defaultProps: { component: Role.div } },
366+
MuiPopover: {
367+
defaultProps: {
368+
component: Role.div,
369+
slotProps: { paper: { role: "dialog" } },
370+
},
371+
},
367372
MuiRadio: {
368373
defaultProps: {
369374
component: Role.span,

0 commit comments

Comments
 (0)