Drawer

A panel that slides in from the edge of the screen, for filters, details, settings or navigation.

import { Drawer } from '@halo-ds/react';

When to use it

A drawer opens over an Overlay without leaving the page, so people keep their place. It has a header, a Content slot that scrolls, and an optional footer with an Actions slot. Use Right for most things, Left for navigation, and Bottom for sheets on phones.

Do

  • Give every drawer a clear title.
  • Put the main action last in the footer, like Apply or Save.
  • Keep people's place in the page, so closing the drawer feels like going back.
  • Use Bottom sheets on phones.

Don't

  • Open a drawer from inside another drawer.
  • Put a whole page of content in a drawer; use a page.
  • Hide the way out: keep × or a Cancel button.
  • Use a drawer for a single question; use a Modal.

Drawer or Modal?

All three open over an Overlay. Pick by how much there is, and whether the page should stay in view.

  • Drawer: Lots of content, or content people come back to, like filters. Part of the page stays in view. The content can scroll.
  • Modal: One short question, or a small focused task like editing a profile. Opens in the middle and blocks the page until it is answered. If people need the page in view while they work, use a drawer.

Props

Drawer props

PropTypeWhat it does
open (required)boolean
onClose (required)() => voidCalled on Escape, the close button, or a click on the overlay.
title (required)ReactNodeFigma: Title.
descriptionReactNodeFigma: Description.
side`"bottom" \"left" \"right" \undefined`Which edge it slides in from. Bottom suits phones. Figma: Side.
size`"sm" \"md" \"lg" \undefined`Width for side drawers: 320, 400 or 560px. Figma: Size.
showClose`boolean \undefined`Figma: Show close.
actionsReactNodeButtons in the footer. Figma: Actions.
closeOnOverlayClick`boolean \undefined`
overlay`"dim" \"blur" \undefined`
childrenReactNodeThe body, which scrolls when it is long. Figma: Content slot.
className`string \undefined`
classNames`Partial<Record<DrawerPart, string>> \undefined`Extra class names for the parts inside the component, by part name, like { header: 'my-header' }.
styles`Partial<Record<DrawerPart, CSSProperties>> \undefined`Inline styles for the parts inside the component, by part name, like { footer: { gap: 4 } }.

It also takes the usual HTML attributes for its element.

Examples

Overview

import { useState } from 'react';
import { Button, Checkbox, Drawer } from '@halo-ds/react';

export default function Example() {
  const [open, setOpen] = useState(false);
  const close = () => setOpen(false);
  return (
    <>
      <Button variant="secondary" onClick={() => setOpen(true)}>Filters</Button>
      <Drawer
        open={open}
        onClose={close}
        title="Filters"
        description="Narrow down the list."
        actions={
          <>
            <Button variant="secondary" onClick={close}>Reset</Button>
            <Button onClick={close}>Show results</Button>
          </>
        }
      >
        <div style={{ display: 'grid', gap: 12 }}>
          <Checkbox label="Active" defaultChecked />
          <Checkbox label="Paused" />
          <Checkbox label="Archived" />
        </div>
      </Drawer>
    </>
  );
}

Sides

From the right (the default), from the left, or as a bottom sheet with a grip.

import { useState } from 'react';
import { Button, Drawer } from '@halo-ds/react';

export default function Demo() {
  const [side, setSide] = useState<'left' | 'right' | 'bottom' | null>(null);
  const close = () => setSide(null);
  return (
    <div className="demo-row">
      <Button variant="secondary" onClick={() => setSide('left')}>Left</Button>
      <Button variant="secondary" onClick={() => setSide('right')}>Right</Button>
      <Button variant="secondary" onClick={() => setSide('bottom')}>Bottom</Button>
      <Drawer
        open={side !== null}
        onClose={close}
        side={side ?? 'right'}
        size="sm"
        title="Filters"
        description="Narrow down the list."
        actions={<Button onClick={close}>Apply</Button>}
      />
    </div>
  );
}

More: https://halodesignsystem.dev/components/drawer