Drawer
An accessible drawer/sidebar component with focus trap and proper ARIA attributes. Supports multiple sides, modal and non-modal modes, and respects reduced motion preferences.
Different Sides
Drawers can appear from any side of the screen.
import { useState } from 'react';
import { AccessibleDrawer } from '@a13y/react';
function Example() {
const [isOpen, setIsOpen] = useState(false);
return (
<>
<button onClick={() => setIsOpen(true)}>
Open Drawer
</button>
<AccessibleDrawer
isOpen={isOpen}
onClose={() => setIsOpen(false)}
side="right"
modal
title="Settings"
>
<div>Drawer content here</div>
</AccessibleDrawer>
</>
);
}Props
| Name | Type | Default | Description |
|---|---|---|---|
isOpen* | boolean | - | Whether the drawer is open |
onClose* | () => void | - | Callback when drawer should close |
side | 'left' | 'right' | 'top' | 'bottom' | 'right' | Side from which the drawer appears |
modal | boolean | true | Whether drawer is modal (blocks interaction with background) |
title | string | - | Drawer title shown in the header |
children* | ReactNode | - | Content to display in the drawer |
className | string | - | Optional CSS class for the drawer |
backdropClassName | string | - | Optional CSS class for the backdrop |
style | React.CSSProperties | - | Optional inline styles |
Keyboard Navigation
EscClose drawer
TabNavigate within drawer (focus trapped)
Accessibility Features
- ✓Uses
role="dialog"with proper ARIA attributes - ✓
aria-modalindicates modal behavior - ✓Focus trap keeps keyboard navigation within drawer when modal
- ✓ESC key closes the drawer
- ✓Prevents body scroll when modal drawer is open
- ✓Respects reduced motion preferences for animations