Back to Shark UI

Drawer

docs/components/drawer

latest11.2 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

Drawer

Copy Markdown

A sliding panel with swipe support.

PreviewCode

Open

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/drawer

Anatomy#

Drawer
├── DrawerTrigger
└── DrawerContent
    ├── DrawerGrabber
    ├── drawer-main
    │ ├── DrawerHeader
    │ ├── DrawerBody
    │ └── DrawerFooter
    │ └── DrawerClose

Usage#

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

Controlled#

Use open and onOpenChange on the root to control the drawer state.

PreviewCode

Open ControlledOpen Uncontrolled

Title & Description#

DrawerHeader supports two usage patterns:

Using props#

Pass title and description props directly to DrawerHeader.

<DrawerHeader 
  title="Allow accessory to connect?" 
  description="Do you want to allow the USB accessory to connect to this device?"
/>

This approach does not require DrawerTitle or DrawerDescription components.

Using components#

Use DrawerTitle and DrawerDescription as children for more control.

<DrawerHeader>
  <DrawerTitle>Allow accessory to connect?</DrawerTitle>
  <DrawerDescription>
    Do you want to allow the USB accessory to connect to this device?
  </DrawerDescription>
</DrawerHeader>

Examples#

Inset Variant#

Use variant="inset" on DrawerContent so the drawer appears as a floating card rather than edge-to-edge.

PreviewCode

Open

Swipe Directions#

Control which direction the drawer slides and swipes using swipeDirection on the root.

PreviewCode

BottomTopLeftRight

Snap Points#

Use snapPoints to allow the drawer to snap to multiple heights.

PreviewCode

Open

Non-Modal#

Use modal={false} to allow interaction with elements outside the drawer.

PreviewCode

Open

Close button#

Use the showCloseButton prop to show a close button in the top-right corner.

PreviewCode

Open

No Drag Area#

Apply the data-no-drag attribute to any element inside the drawer to prevent dragging from starting on it.

PreviewCode

Open

Non Draggable#

Set draggable={false} on DrawerContent to disable drag-to-dismiss on the panel.

The drawer can still be dragged by the grabber.

PreviewCode

Open

Custom spacing#

Use [--space:--spacing("value")] on DrawerContent to adjust internal spacing.

Default spacing is --spacing(6).

PreviewCode

Open

You can use breakpoint utilities to change the internal spacing at different screen sizes.

md:[--space:--spacing(6)] lg:[--space:--spacing(8)]

API Reference#

Drawer#

Root element of the drawer.

PropTypeDefault
openboolean-
defaultOpenbooleanfalse
onOpenChange({ open }: OpenChangeDetails) => void-
swipeDirection`"up""down"
snapPoints`(numberstring)[]`
defaultSnapPoint`numberstring
snapToSequentialPointsbooleanfalse
closeThresholdnumber0.25
swipeVelocityThresholdnumber700
preventDragOnScrollbooleantrue
modalbooleantrue
closeOnEscapebooleantrue
closeOnInteractOutsidebooleantrue
classNamestring-

DrawerTrigger#

Opens the drawer on click. Use asChild for custom trigger elements.

PropTypeDefault
asChildbooleanfalse
classNamestring-

DrawerContent#

Holds the drawer panel. Supports swipe-to-close; direction inherited from root swipeDirection.

PropTypeDefault
variant`"default""inset"`
showBarbooleantrue
showCloseButtonbooleanfalse
draggablebooleantrue
classNamestring-
AttributeDefault
--bleed--spacing(12)
--space--spacing(4)

DrawerHeader#

Header area for title and description. Accepts props or children.

PropTypeDefault
titlestring-
descriptionstring-
classNamestring-

DrawerTitle#

Accessible title for the drawer. Announced to screen readers.

PropTypeDefault
asChildbooleanfalse
classNamestring-

DrawerDescription#

Accessible description for the drawer. Announced to screen readers.

PropTypeDefault
asChildbooleanfalse
classNamestring-

DrawerBody#

Scrollable body content. Uses ScrollArea for overflow. Supports scrollFade for gradient edges.

PropTypeDefault
scrollFadebooleanfalse
classNamestring-

DrawerFooter#

Footer area for action buttons.

PropTypeDefault
classNamestring-

DrawerClose#

Closes the drawer on click. Use asChild for custom close elements.

PropTypeDefault
asChildbooleanfalse
classNamestring-

For a complete list of props, see the Ark UI documentation.

[

Previous page

Dialog ](/docs/components/dialog)[

Next page

Editable ](/docs/components/editable)

On This Page

InstallationAnatomyUsageControlledTitle & DescriptionUsing propsUsing componentsExamplesInset VariantSwipe DirectionsSnap PointsNon-ModalClose buttonNo Drag AreaNon DraggableCustom spacingAPI ReferenceDrawerDrawerTriggerDrawerContentDrawerHeaderDrawerTitleDrawerDescriptionDrawerBodyDrawerFooterDrawerClose