Skip to main content
Back to Home

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

NameTypeDefaultDescription
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
modalbooleantrueWhether drawer is modal (blocks interaction with background)
titlestring-Drawer title shown in the header
children*ReactNode-Content to display in the drawer
classNamestring-Optional CSS class for the drawer
backdropClassNamestring-Optional CSS class for the backdrop
styleReact.CSSProperties-Optional inline styles

Keyboard Navigation

EscClose drawer
TabNavigate within drawer (focus trapped)

Accessibility Features

  • Uses role="dialog" with proper ARIA attributes
  • aria-modal indicates 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