Skip to content
flyingsalmon

Drawer

A modal panel at the right edge for content that accompanies the page: filters for a list, the detail of a selected row.

  • Kyoto · 12 to 19 Oct, 3 travellers
  • Lisbon · 3 to 6 Mar, 2 travellers
  • Hanoi · 20 to 27 Apr, 4 travellers
  • Da Nang · 1 to 8 Aug, 2 travellers

Installation

npx shadcn@latest add @flyingsalmon/drawer

Usage

import { Button, ButtonVariant } from '@/components/ui/button'
import {
  Drawer,
  DrawerBody,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerTitle,
  DrawerTrigger,
} from '@/components/ui/drawer'

export function DrawerUsage() {
  return (
    <Drawer>
      <DrawerTrigger>
        <Button variant={ButtonVariant.Outline}>Trip details</Button>
      </DrawerTrigger>
      <DrawerContent>
        <DrawerTitle>Kyoto in autumn</DrawerTitle>
        <DrawerDescription>12 to 19 October, 3 travellers.</DrawerDescription>
        <DrawerBody>
          Three nights at Ryokan Aoi, then on to Kanazawa.
        </DrawerBody>
        <DrawerFooter>
          <DrawerClose>
            <Button variant={ButtonVariant.Outline}>Close</Button>
          </DrawerClose>
        </DrawerFooter>
      </DrawerContent>
    </Drawer>
  )
}

Examples

The detail of a selected row

One drawer serves every row. The app holds the selected row and drives open, so there is no DrawerTrigger: the buttons in the table are plain buttons that happen to open it.

StopNights
Kyoto3
Kanazawa2
Tokyo4

Closing on submit

Save closes the panel and the trip card shows the new name and dates. The card is where the traveller was already looking, so it carries the result.

Kyoto in autumn

Oct 12, 2026 to Oct 19, 2026

Fit to content

fitContent grows the panel to the width of a table. Remove it and the same table scrolls inside the standard panel.

A form that survives a stray click

dismissible={false} ignores a click on the page beside the panel. Escape and the close button still work.

Waiting inside the drawer

pending holds every exit while the address is looked up, because the answer decides what happens next. A wrong address keeps the panel open with the error on the field.

Guidelines

When to use

  • For filters on a list, so the list stays in view and changes while the traveller adjusts them.
  • For the detail of one selected row, with the table still beside it.
  • For a short edit form where the item being edited should stay visible.

When not to use

  • Use Dialog to confirm an action or stop the page for a decision. A dialog sits in the centre and the page behind it stops mattering.
  • Use Sidebar to move between sections of the app. Navigation belongs to the sidebar at every width, including the strip it collapses to on a narrow screen.
  • Use Notice to show the result of an action. A result needs only to be seen, not answered.

Do and don’t

  • Do
    Close a form drawer on submit and show the result on the item that changed.The item is still on screen beside the panel, so the updated trip is the clearest confirmation.
  • Do
    Show one selected thing at a time. Choosing another row swaps the drawer’s content.The drawer is the detail of the current selection. A second panel would cover the list it belongs to.
  • Don’t
    Turn a detail drawer into an editor. Its action opens a dialog for a change that reshapes the trip.Detail is for reading beside the list. A change with consequences needs the full stop of a dialog and its own confirm.
  • Don’t
    Put the destructive confirmation of a trip in a drawer.A confirmation demands a decision, and a drawer invites the traveller to keep working on the page behind it.

Accessibility

KeyDescription
EnterSpaceOn the trigger, opens the drawer and moves focus to its first control.
TabShift+TabCycles through the controls inside the drawer. The close button comes last.
EscapeCloses the drawer and returns focus to the trigger. Does nothing while the drawer is pending.

The drawer is a modal dialog. It is labelled by its required title and described by DrawerDescription when there is one, and it sets aria-busy while pending. Focus lands on the first body or footer control, never the close button, and returns to the trigger on close. Everything outside an open drawer is hidden from assistive technology.

A drawer opened from your own state has no DrawerTrigger, so the button that opens it is a plain button without aria-expanded.

API

Drawer

The root. It takes the dialog root's props except size, so every prop means what it means on a dialog.

PropTypeDefaultDescription
openboolean–The controlled open state.
defaultOpenbooleanfalseThe initial open state when uncontrolled.
onOpenChange(open: boolean) => void–Called when the drawer opens or closes.
dismissiblebooleantruefalse ignores a click outside. Escape and the close button still work.
pendingbooleanfalseBlocks Escape, a click outside, and the close button, disables the close button, and sets aria-busy. Keep it for an answer the next step depends on, such as looking up an invite; a plain save closes the drawer at once.

DrawerContent

The panel. Renders the scrim and the close button for you.

PropTypeDefaultDescription
fitContentbooleanfalseGrows the panel to the width of its body, between the standard width and the viewport. Loose prose has no widest layout but one long line and pushes the panel to its cap, so give a body like that its own width.
onOpenAutoFocus(event: Event) => void–Runs as focus moves in. Prevent the default to place focus yourself.
onCloseAutoFocus(event: Event) => void–Runs as focus returns. Prevent the default to send it elsewhere.

DrawerTrigger and DrawerClose take one element, usually a Button. DrawerTitle is required. DrawerDescription, DrawerBody, and DrawerFooter are optional and take the props of the element they render, typed as DrawerTitleProps, DrawerDescriptionProps, DrawerBodyProps, and DrawerFooterProps. DrawerBody is the only part that scrolls.

  • Dialog

    The centred modal for a decision that stops the page.
  • Sidebar

    Where app navigation lives.
  • Table

    The rows whose detail a drawer often shows.
  • Accessibility

    The focus and contrast rules every component follows.
  • Motion

    The springs the panel enters and leaves on.