UI.MD

Drawer

A panel that slides in from the edge of the screen.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/drawer.json

Usage

import { Drawer, DrawerTrigger, DrawerContent, DrawerHeader, DrawerBody, DrawerFooter, DrawerTitle, DrawerDescription } from "@/components/ui/drawer"

Examples

Default

The prose layout: a short form you fill in and dismiss. The panel pads itself and spaces its children, so no wrapper is needed. If the content can outgrow the screen, use panel instead.

Panel

The panel layout for a surface you work in: a fixed header bar, a DrawerBody that scrolls under it, and a footer pinned to the bottom. Set layout once on DrawerContent and every part reads it.

API Reference

PropTypeDefaultDescription
sideDrawerContent"top" | "right" | "bottom" | "left""right"Edge of the screen the drawer slides in from.
sizeDrawerContent"sm" | "md" | "lg" | "xl" | "2xl""sm"Maximum width of the panel for left/right drawers; top/bottom drawers span the full width.
layoutDrawerContent"prose" | "panel""prose"prose is the short form: the popup pads itself, spaces its children, and floats a close in the corner. panel is the application surface: the popup owns no padding, DrawerHeader becomes a fixed 64px bar with a wall-to-wall hairline and an inline close, and each region pads its own contents. Set once here; the parts read it, so a panel needs no other overrides.
showCloseButtonDrawerContentbooleantrue, or false under layout="panel"Shows the X close button floating in the top corner. Off by default in a panel, where the header bar carries an inline one instead.
closeDrawerHeaderReactNode-Replaces the panel bar's stock close button, for a header that needs its own accessible name, icon, or analytics attribute. Supply the whole control including its trigger: <DrawerClose render={<MyButton />} />. Read under layout="panel" only; under prose the close belongs to DrawerContent.
showCancelButtonDrawerFooterbooleanfalseAppends a ghost Cancel button that closes the drawer.