Skip to content

Commit ac072e7

Browse files
Merge pull request #884 from Availity/fix/drawer-a11y
refactor(mui-drawer): ensure slots and slotProps work
2 parents 6e2482d + 5ba5600 commit ac072e7

2 files changed

Lines changed: 52 additions & 26 deletions

File tree

packages/drawer/src/lib/Drawer.stories.tsx

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Box } from '@availity/mui-layout';
55
import { ArrowsRotateIcon, ChartPieIcon, InboxIcon, SendIcon, SettingsIcon } from '@availity/mui-icon';
66
import { Checkbox } from '@availity/mui-checkbox';
77
import { FormControl, FormControlLabel, FormGroup, FormLabel } from '@availity/mui-form-utils';
8-
import { List, ListItemButton, ListItemIcon, ListItemText } from '@availity/mui-list';
8+
import { List, ListItem, ListItemButton, ListItemIcon, ListItemText } from '@availity/mui-list';
99
import { Drawer, DrawerProps } from './Drawer';
1010

1111
const meta: Meta<typeof Drawer> = {
@@ -31,6 +31,11 @@ export const _Drawer: StoryObj<typeof Drawer> = {
3131
);
3232
},
3333
args: {
34+
slotProps: {
35+
paper: {
36+
'aria-label': 'test-drawer',
37+
},
38+
},
3439
children: `Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quos blanditiis tenetur unde suscipit, quam
3540
beatae rerum inventore consectetur, neque doloribus, cupiditate numquam dignissimos laborum fugiat deleniti? Eum
3641
quasi quidem quibusdam.`,
@@ -60,32 +65,45 @@ export const _NavDrawer: StoryObj<typeof Drawer> = {
6065
},
6166
args: {
6267
anchor: 'left',
68+
slotProps: {
69+
paper: {
70+
'aria-label': 'navigation drawer',
71+
},
72+
},
6373
children: (
6474
<List disablePadding>
65-
<ListItemButton divider>
66-
<ListItemIcon>
67-
<InboxIcon />
68-
</ListItemIcon>
69-
<ListItemText>Inbox</ListItemText>
70-
</ListItemButton>
71-
<ListItemButton divider>
72-
<ListItemIcon>
73-
<SendIcon />
74-
</ListItemIcon>
75-
<ListItemText>Sent</ListItemText>
76-
</ListItemButton>
77-
<ListItemButton divider>
78-
<ListItemIcon>
79-
<ChartPieIcon />
80-
</ListItemIcon>
81-
<ListItemText>Reporting</ListItemText>
82-
</ListItemButton>
83-
<ListItemButton divider>
84-
<ListItemIcon>
85-
<SettingsIcon />
86-
</ListItemIcon>
87-
<ListItemText>Settings</ListItemText>
88-
</ListItemButton>
75+
<ListItem disablePadding>
76+
<ListItemButton>
77+
<ListItemIcon>
78+
<InboxIcon />
79+
</ListItemIcon>
80+
<ListItemText>Inbox</ListItemText>
81+
</ListItemButton>
82+
</ListItem>
83+
<ListItem disablePadding>
84+
<ListItemButton>
85+
<ListItemIcon>
86+
<SendIcon />
87+
</ListItemIcon>
88+
<ListItemText>Sent</ListItemText>
89+
</ListItemButton>
90+
</ListItem>
91+
<ListItem disablePadding>
92+
<ListItemButton>
93+
<ListItemIcon>
94+
<ChartPieIcon />
95+
</ListItemIcon>
96+
<ListItemText>Reporting</ListItemText>
97+
</ListItemButton>
98+
</ListItem>
99+
<ListItem disablePadding>
100+
<ListItemButton>
101+
<ListItemIcon>
102+
<SettingsIcon />
103+
</ListItemIcon>
104+
<ListItemText>Settings</ListItemText>
105+
</ListItemButton>
106+
</ListItem>
89107
</List>
90108
),
91109
},
@@ -121,6 +139,7 @@ export const _PersistentDrawer: StoryObj<typeof Drawer> = {
121139
variant: 'persistent',
122140
slotProps: {
123141
paper: {
142+
'aria-label': 'persistent drawer',
124143
variant: 'outlined',
125144
},
126145
},

packages/drawer/src/lib/Drawer.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export const Drawer = ({
3939
header,
4040
onClose,
4141
size = 'medium',
42+
slots,
43+
slotProps,
4244
...rest
4345
}: DrawerProps): React.JSX.Element => {
4446
const drawerHeader = (
@@ -71,23 +73,28 @@ export const Drawer = ({
7173
anchor={anchor}
7274
onClose={onClose}
7375
slots={{
76+
...slots,
7477
backdrop: Backdrop,
7578
}}
7679
slotProps={{
80+
...slotProps,
7781
paper: {
82+
...(slotProps?.paper as any),
7883
sx:
7984
anchor === 'left' || anchor === 'right'
8085
? {
86+
...(slotProps?.paper as any)?.sx,
8187
width,
8288
[`@media (max-width: ${breakpoint}px)`]: {
8389
width: 'calc(100% - 24px)',
8490
},
8591
}
86-
: undefined,
92+
: (slotProps?.paper as any)?.sx,
8793
},
8894
transition: {
8995
easing: { enter: 'cubic-bezier(0.4, 0, 1, 1)', exit: 'cubic-bezier(0.0, 0, 0.2, 1)' },
9096
timeout: { enter: 225, exit: 195 },
97+
...slotProps?.transition,
9198
},
9299
}}
93100
>

0 commit comments

Comments
 (0)