Drawer
Web/MobileA panel that slides in from an edge of the screen - typically the bottom - with dim overlay chrome.
Installation
pnpm dlx cubix-ui@latest add drawer --base radixAdd the following to your global styles. On iOS Safari, the drawer overlay is absolutely positioned and requires a positioned body to cover the viewport after the page is scrolled.
body {
position: relative;
}Usage
import { Button } from "@/components/cubix/button"
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/components/cubix/drawer"
<Drawer>
<DrawerTrigger render={<Button variant="outline" size="sm" />}>
باز کردن
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>کاملاً مطمئن هستید؟</DrawerTitle>
</DrawerHeader>
<div className="p-4 text-description text-muted-foreground">
پس از تأیید، تغییرات اعمال میشود.
</div>
<DrawerFooter>
<DrawerClose render={<Button variant="outline" />}>انصراف</DrawerClose>
<Button type="submit">تأیید</Button>
</DrawerFooter>
</DrawerContent>
</Drawer>
Composition
Use the following composition to build a Drawer:
Drawer
├── DrawerTrigger
└── DrawerContent
├── DrawerHeader
│ ├── DrawerTitle
│ └── DrawerDescription
└── DrawerFooterDrawerContent composes the portal, overlay, viewport, and popup. For lower-level control, DrawerPortal, DrawerOverlay, and DrawerSwipeHandle are also exported from the Base variant.
Examples
Custom Sizes
A vertical drawer sizes itself to its content and is capped at calc(100dvh - 6rem) by default. Override height with h-* / max-h-* or width with w-* / max-w-* on DrawerContent.
Position
Use the swipeDirection prop to set the side of the drawer. Options are up, right, down, and left. Default is down.
Swipe Handle
Use showSwipeHandle on Drawer to render a swipe handle (Base UI).
Nested
Open drawers from inside another drawer. Parent drawers stay mounted and stack behind the frontmost drawer.
Non Modal
Set modal={false} to allow interaction with the rest of the page. Combine with disablePointerDismissal to prevent closing on outside presses.
Snap Points
Use snapPoints to snap a vertical drawer to preset heights. Numbers between 0 and 1 are viewport fractions; values greater than 1 are pixels. Strings support px and rem.
API Reference
Note: Base UI supports swipe, snap points, nested drawers, and showSwipeHandle. Radix (vaul) supports swipe/snap with a direction / swipeDirection alias. React Aria is a solid modal drawer with matching chrome (no swipe/snap). Overlay uses bg-overlay-strong (dim, not blur).
Drawer
The container that wraps the trigger and content and manages open state.
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | - | Controlled open state. Omit to use uncontrolled mode. |
| defaultOpen | boolean | false | Initial open state when uncontrolled. |
| onOpenChange | (open: boolean) => void | - | Called when the open state changes. |
| swipeDirection | "up" | "right" | "down" | "left" | "down" | Side the drawer opens from (shadcn / Base UI). Radix and Aria map up→top and down→bottom. |
| direction | "top" | "right" | "bottom" | "left" | "bottom" | Optional alias for older Vaul-style APIs. Prefer swipeDirection in new code. |
| showSwipeHandle | boolean | false | Base UI only: render a swipe handle inside the popup. |
| snapPoints | (number | string)[] | - | Base/Radix: preset heights for vertical drawers. Aria ignores snap points. |
| modal | boolean | "trap-focus" | true | Base: when false, page stays interactive. Use trap-focus to keep focus inside while leaving pointer/scroll free. |
| disablePointerDismissal | boolean | - | Base: prevent closing on outside press (useful with modal={false}). |
| children | React.ReactNode | - | The trigger and drawer content. |
DrawerTrigger / DrawerClose
The elements that open and close the drawer. Compose both with Cubix Button via render.
| Prop | Type | Default | Description |
|---|---|---|---|
| render | React.ReactElement | - | Render the trigger or close control as another Cubix element (e.g. a Button). |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
DrawerContent
The sliding panel rendered with a backdrop.
| Prop | Type | Default | Description |
|---|---|---|---|
| dir | "ltr" | "rtl" | "rtl" | Text direction of the portaled panel. Defaults to RTL for Persian-first layouts. |
| lang | string | "fa" | Language attribute applied when dir is "rtl". Pass dir="ltr" to omit it. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). Use h-*/max-h-* or w-*/max-w-* for custom sizes. |
DrawerHeader / DrawerFooter
Layout regions of the drawer content. Footer places actions side by side with equal widths.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
DrawerTitle / DrawerDescription
The title and supporting text of the drawer.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |