View fulldotdev/ui on GitHub

Drawer

A drawer component for React.

Installation

npx shadcn@latest add @fulldev/drawer

Usage

import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
<Drawer>
  <DrawerTrigger render={<Button variant="outline" />}>Open</DrawerTrigger>
  <DrawerContent>
    <DrawerHeader>
      <DrawerTitle>Are you absolutely sure?</DrawerTitle>
      <DrawerDescription>This action cannot be undone.</DrawerDescription>
    </DrawerHeader>
    <div className="p-4">{/* Content here */}</div>
    <DrawerFooter>
      <Button>Submit</Button>
      <DrawerClose render={<Button variant="outline" />}>Cancel</DrawerClose>
    </DrawerFooter>
  </DrawerContent>
</Drawer>

Composition

Use the following composition to build a Drawer:

Drawer
├── DrawerTrigger
└── DrawerContent
    ├── DrawerHeader
    │   ├── DrawerTitle
    │   └── DrawerDescription
    └── DrawerFooter

Custom Sizes

A vertical drawer sizes itself to its content and is capped at calc(100dvh - 6rem) by default.

<DrawerContent className="h-[50vh]">

Position

Use the swipeDirection prop to set the side of the drawer.

Swipe Handle

Use showSwipeHandle on Drawer to render a swipe handle.

Nested

Open drawers from inside another drawer.

Non Modal

Set modal={false} to allow interaction with the rest of the page while the drawer is open.

Snap Points

Use snapPoints to snap a drawer to preset heights.

Responsive

You can combine the Dialog and Drawer components to create a responsive dialog.

Migrating from Vaul

The base drawer now uses Base UI instead of Vaul.

- npm install vaul
+ npm install @base-ui/react

API Reference

Source: react/src/components/ui/drawer.tsx

See the Base UI documentation for the full API reference.