Drawer

Accessibility

Drawer

Keyboard interaction

  • Escape key closes the drawer
  • Tab key cycles through focusable elements within the drawer
  • Shift+Tab navigates backward through focusable elements

ARIA attributes

Automatically applied attributes

  • role="dialog" - Identifies the drawer as a dialog
  • aria-modal="true" - Indicates that the drawer is modal and blocks interaction with other page content
  • aria-label - Automatically set to the title prop value, or can be overridden with the ariaLabel prop

Optional attributes

NameTypeDescription
ariaLabelstringText that labels the drawer content. Think of it as the title of the drawer. This should be used if title is not defined.

Close button

Toggle element

  • aria-haspopup="dialog" - Indicates that the element triggers a dialog
  • aria-expanded - Indicates whether the drawer is open (true) or closed (false)
  • aria-controls - The ID of the drawer element

Example implementation

const [drawerOpen, setDrawerOpen] = React.useState(false);
const drawerId = "my-drawer";
return (
<>
<Button
onClick={() => setDrawerOpen(true)}
aria-haspopup="dialog"
aria-expanded={drawerOpen}
aria-controls={drawerOpen ? drawerId : undefined}
>
Open Settings
</Button>
<Drawer
id={drawerId}
shown={drawerOpen}
onClose={() => setDrawerOpen(false)}
title="Settings"
>
{/* Drawer content */}
</Drawer>
</>
);

Focus management with triggerRef

const triggerButtonRef = React.useRef(null);
return (
<>
<Button ref={triggerButtonRef} onClick={() => setDrawerOpen(true)}>
Open Drawer
</Button>
<Drawer
shown={drawerOpen}
triggerRef={triggerButtonRef}
onClose={() => setDrawerOpen(false)}
>
{/* Drawer content */}
</Drawer>
</>
);