Components

Drawer

A panel that slides in from the edge of the screen and can be swiped away, for details beside a list or a sheet on a phone. Built on ui-sdk’s Drawer.

Usage

import {
  Drawer,
  DrawerBody,
  DrawerCloseButton,
  DrawerContent,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from 'nyctoui/drawer'

<Drawer side="right">
  <DrawerTrigger render={<Button />}>Open issue</DrawerTrigger>
  <DrawerContent>
    <DrawerHeader>
      <DrawerTitle>ENG-142 Offline mode for drafts</DrawerTitle>
      <DrawerCloseButton />
    </DrawerHeader>
    <DrawerBody>…</DrawerBody>
  </DrawerContent>
</Drawer>

The panel floats 8px from the screen edges with the same surface, border and radius as a dialog. It shares the dialog’s layout parts, so a header, a body and a footer look alike in both.

Drag or swipe the panel back toward its edge to close it; a quick flick closes it faster. Esc and a tap on the backdrop work too. With reduced motion the panel appears without sliding.

Good for

  • An issue’s details sliding in beside the list in a project tool, while the list stays visible.
  • Filters on a phone in a shopping app, as a bottom sheet.
  • A shopping cart that slides in from the side of a store.
  • A row inspector in an admin table, with the record’s fields and history.

Anatomy

<Drawer>
  <DrawerTrigger />
  <DrawerContent>
    <DrawerHeader>
      <DrawerTitle />
      <DrawerCloseButton />
      <DrawerDescription />
    </DrawerHeader>
    <DrawerBody />
    <DrawerFooter>
      <DrawerClose />
    </DrawerFooter>
  </DrawerContent>
</Drawer>

Examples

Left

side="left" suits navigation on a small screen. Close the drawer when a link is followed.

Bottom sheet

side="bottom" is a sheet with a grab handle, for a short list of choices on a phone, where the thumb can reach them. Swipe it down to dismiss.

With actions

A DrawerFooter stays pinned to the bottom of the panel while the body scrolls.

Sizes

size sets the width of a side drawer. A bottom drawer spans the screen, up to 640px.

Best practices

Do
  • Use it for detail that belongs to a list, so people keep their place in the list behind it.
  • Use side="bottom" for a sheet on phones, where a side drawer leaves little room.
  • Give every drawer a visible close, such as DrawerCloseButton, especially when it isn’t modal and there’s no backdrop to click.
  • Keep the last item’s content in place while the drawer slides out, so it doesn’t go blank on the way.
  • Set disablePointerDismissal when the drawer holds a form.
Don’t
  • Use a drawer for a short confirmation or a two-field form. That’s a dialog.
  • Open a drawer from inside another drawer.
  • Use a drawer for content that should push the page aside. That’s a resizable panel or a sidebar layout.

API reference

Drawer

Holds the open state and the swipe gesture. Renders no element.

PropTypeDefault
side
The edge the panel slides in from and is swiped back to.
'left' | 'right' | 'bottom''right'
defaultOpen
Starts open. For uncontrolled use.
booleanfalse
open
Whether the drawer is open. For controlled use.
boolean—
onOpenChange
Called when the drawer opens or closes.
(open: boolean, details) => void—
modal
Traps focus, locks page scroll and blocks the page. false leaves the page usable.
boolean | 'trap-focus'true
disablePointerDismissal
Keeps the drawer open on a tap outside.
booleanfalse

DrawerTrigger

The button that opens the drawer. Renders a <button>.

PropTypeDefault
render
Replaces the rendered element, e.g. render={<Button />}.
ReactElement | function—

DrawerContent

The panel, with the backdrop behind it. Renders a <div> in the top layer.

PropTypeDefault
size
Width of a side drawer: 320, 400 or 560px.
'sm' | 'md' | 'lg''md'
container
Element to render into instead of the page body, such as a Phone screen.
HTMLElement | RefObject | null—
initialFocus
The element to focus on open. Defaults to the first focusable one.
boolean | RefObject | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

DrawerHeader

Lays out the title, description and close button. Renders a <div>.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

DrawerTitle

Labels the drawer. Renders an <h2>.

PropTypeDefault
render
Replaces the rendered element, e.g. render={<Button />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

DrawerDescription

Describes the drawer to assistive tech. Renders a <p>.

PropTypeDefault
render
Replaces the rendered element, e.g. render={<Button />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

DrawerBody

Fills the panel and scrolls. Renders a <div>.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

DrawerFooter

Actions pinned to the bottom, aligned to the end. Renders a <div>.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

DrawerClose

Closes the drawer. Renders a <button>.

PropTypeDefault
render
Replaces the rendered element, e.g. render={<Button />}.
ReactElement | function—

DrawerCloseButton

A ghost icon Button with an X that closes the drawer.

PropTypeDefault
aria-label
The accessible name of the button.
string'Close'
sx
StyleX styles merged after the built-in ones.
StyleXStyles—