Prototyper UI

Drawer

slide-in panel anchored to any viewport edge

Loading...

Installation

pnpm dlx shadcn@latest add https://prototyper-ui.com/r/drawer.json
npx shadcn@latest add https://prototyper-ui.com/r/drawer.json
yarn dlx shadcn@latest add https://prototyper-ui.com/r/drawer.json
bunx --bun shadcn@latest add https://prototyper-ui.com/r/drawer.json

This will add the following files to your project:

  • components/ui/drawer.tsx

Usage

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

<Drawer>
  <DrawerTrigger>Open</DrawerTrigger>
  <DrawerContent>
    <DrawerHeader>
      <DrawerTitle>Drawer Title</DrawerTitle>
      <DrawerDescription>Drawer description.</DrawerDescription>
    </DrawerHeader>
  </DrawerContent>
</Drawer>

Anatomy

<Drawer>
  <DrawerTrigger />
  <DrawerContent>
    <DrawerHeader>
      <DrawerTitle />
      <DrawerDescription />
    </DrawerHeader>
    {/* your content */}
    <DrawerFooter>
      <DrawerClose />
    </DrawerFooter>
  </DrawerContent>
</Drawer>
Sub-componentdata-slotPurposeRequired
DrawerdrawerRoot provider, manages open/close stateYes
DrawerTriggerdrawer-triggerButton that opens the drawerYes
DrawerPortaldrawer-portalRenders children into a portalNo
DrawerOverlaydrawer-overlayBackdrop behind the drawerNo
DrawerContentdrawer-contentThe drawer popup panelYes
DrawerHeaderdrawer-headerFlex container for title and descriptionNo
DrawerTitledrawer-titleAccessible title for the drawerYes
DrawerDescriptiondrawer-descriptionAccessible description for the drawerNo
DrawerFooterdrawer-footerFlex container for action buttonsNo
DrawerClosedrawer-closeButton that closes the drawerNo

Examples

Directions

Use the direction prop on DrawerContent to slide the drawer in from any edge.

Loading...

Styling

Data Slots

Use data-slot attributes to target specific parts of the drawer:

Slot nameElement
drawerRoot provider (no DOM element rendered)
drawer-triggerThe trigger button
drawer-portalPortal wrapper
drawer-overlayBackdrop overlay
drawer-contentThe popup panel
drawer-headerHeader container (title + description)
drawer-titleTitle heading
drawer-descriptionDescription paragraph
drawer-footerFooter container (action buttons)
drawer-closeClose button(s)

Customization Examples

/* Make side drawers wider */
[data-slot="drawer-content"][data-drawer-direction="right"],
[data-slot="drawer-content"][data-drawer-direction="left"] {
  @apply sm:max-w-md;
}

/* Custom overlay color */
[data-slot="drawer-overlay"] {
  @apply bg-black/30;
}
{/* Override direction via prop */}
<DrawerContent direction="right">
  {/* ... */}
</DrawerContent>

API Reference

Drawer

Root component that manages open/close state.

Prop

Type

All Base UI Drawer.Root props are forwarded via ...props.

DrawerTrigger

Button that opens the drawer when clicked.

Prop

Type

All Base UI Drawer.Trigger props are forwarded via ...props.

DrawerContent

The popup panel rendered inside a portal with an overlay backdrop. Includes an automatic drag handle when direction is "bottom".

Prop

Type

All Base UI Drawer.Popup props are forwarded via ...props.

DrawerHeader

Flex column container for title and description.

Prop

Type

All standard div props are forwarded via ...props.

DrawerFooter

Flex column container for action buttons.

Prop

Type

All standard div props are forwarded via ...props.

DrawerTitle

Accessible title for the drawer, rendered as a heading.

Prop

Type

All Base UI Drawer.Title props are forwarded via ...props.

DrawerDescription

Accessible description rendered below the title.

Prop

Type

All Base UI Drawer.Description props are forwarded via ...props.

DrawerClose

Button that closes the drawer when clicked.

All Base UI Drawer.Close props are forwarded via ...props.

DrawerOverlay

Backdrop overlay behind the drawer.

Prop

Type

All Base UI Drawer.Backdrop props are forwarded via ...props.

DrawerPortal

Renders children into a React portal.

Prop

Type

All Base UI Drawer.Portal props are forwarded via ...props.

Accessibility

Keyboard Interactions

KeyAction
EscapeCloses the drawer
TabMoves focus to the next focusable element within the drawer
Shift+TabMoves focus to the previous focusable element within the drawer

ARIA Attributes

  • DrawerContent receives role="dialog".
  • aria-modal="true" is set when the drawer is modal.
  • aria-labelledby is automatically linked to DrawerTitle.
  • aria-describedby is automatically linked to DrawerDescription.
  • Focus is trapped inside the drawer while it is open.
  • Focus returns to the trigger element when the drawer closes.

On this page