[ Overlays ]

Drawer

A panel that slides in from an edge of the screen and slides back out when closed. It shares all of Modal's behaviour (focus trap, scroll lock, Escape to close) and adds placement, size and a floating style with rounded corners. Bottom sheets get a grab handle.

3 examplesDark modeAccessible

Import#

import { Drawer } from 'reusify-ui';

When to use#

  • Filters, settings and detail views that keep the main page in context.
  • Mobile navigation menus (placement="left").
  • Longer forms that would feel cramped in a Modal.

Examples#

Filters panel#

const { isOpen, open, close } = useDisclosure();

<Button variant="secondary" onClick={open}>Open filters</Button>
<Drawer
  open={isOpen}
  onClose={close}
  title="Filters"
  description="Narrow down the results."
  footer={
    <>
      <Button variant="ghost" onClick={resetFilters}>Reset</Button>
      <Button onClick={close}>Apply</Button>
    </>
  }
>
  <Checkbox label="In stock" />
  <Checkbox label="On sale" />
</Drawer>

Placement & size#

size accepts sm (20rem), md (24rem), lg (32rem) or any CSS length. It sets the width for left/right and the height for top/bottom.

<Drawer placement="left" … />
<Drawer placement="right" size="lg" … />
<Drawer placement="top" size="16rem" … />
<Drawer placement="bottom" size={300} … />

Floating#

floating insets the drawer from every edge and rounds all its corners, like a card sliding in. It works with every placement. Close it to see the exit animation.

<Drawer floating placement="right" open={isOpen} onClose={close} title="Notifications" … />
<Drawer floating placement="bottom" size="18rem" open={isOpen} onClose={close} title="Share" … />

API reference#

<Drawer />

Accepts every Modal prop except size, plus:

placement'right'
'left' | 'right' | 'top' | 'bottom'

Edge the drawer slides in from.

size'md'
'sm' | 'md' | 'lg' | string | number

Width (left/right) or height (top/bottom). Numbers are pixels.

floatingfalse
boolean

Inset from the edges with fully rounded corners.

open*-
boolean

Whether the drawer is visible.

onClose*-
() => void

Called on Escape, overlay click or the close button.

title / description / footer-
ReactNode

Same as Modal.

Accessibility#

  • Same as Modal: role="dialog", focus trap, scroll lock and focus restore.
  • Enter and exit slides are turned off when the user prefers reduced motion.