Examples
Side panel with bounded content
Focus stays inside the modal panel; the body scrolls while the header and footer remain visible.
Open a right-side project details panel
"use client";
import { useState } from "react";
import { Button } from "@phuctech/ui/components/button";
import {
Drawer,
DrawerBody,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@phuctech/ui/components/drawer";
export function Example() {
const [open, setOpen] = useState(false);
return (
<Drawer open={open} onOpenChange={setOpen}>
<DrawerTrigger render={<Button variant="outline">Open project details</Button>} />
<DrawerContent side="right">
<DrawerHeader><DrawerTitle>Atlas onboarding</DrawerTitle><DrawerDescription>Review project status and recent activity.</DrawerDescription></DrawerHeader>
<DrawerBody><p className="mb-3">The project keeps setup steps and owners together.</p><p>Long details stay in this scrollable region while the heading and actions remain visible.</p></DrawerBody>
<DrawerFooter><DrawerClose render={<Button variant="outline">Close</Button>} /></DrawerFooter>
</DrawerContent>
</Drawer>
);
}
Try the placement
Choose an edge; side drawers expand to the available mobile width.
Drawer placement playground
import { Button } from "@phuctech/ui/components/button";
import { Drawer, DrawerBody, DrawerContent, DrawerHeader, DrawerTitle, DrawerTrigger } from "@phuctech/ui/components/drawer";
export function Example() {
return <Drawer><DrawerTrigger render={<Button>Open details</Button>} /><DrawerContent side="right"><DrawerHeader><DrawerTitle>Project details</DrawerTitle></DrawerHeader><DrawerBody>Long content scrolls inside the panel.</DrawerBody></DrawerContent></Drawer>;
}When to use
Use Drawer for a related task or detail panel that should keep the current page in context. It reuses Dialog's modal focus handling, Escape behavior, portal, and scroll lock. On small screens the panel expands to the available width or height.
Usage
import { Button } from "@phuctech/ui/components/button";
import { Drawer, DrawerBody, DrawerContent, DrawerHeader, DrawerTitle, DrawerTrigger } from "@phuctech/ui/components/drawer";
<Drawer>
<DrawerTrigger render={<Button type="button">Open details</Button>} />
<DrawerContent side="right">
<DrawerHeader><DrawerTitle>Project details</DrawerTitle></DrawerHeader>
<DrawerBody>Long content scrolls inside the panel.</DrawerBody>
</DrawerContent>
</Drawer>API
Tokens
Accessibility
Drawer inherits Dialog's focus trap, Escape close, modal backdrop, and focus return. Provide a title and keep the body as the only growing scroll region; the trigger must have a visible label and the close action must remain reachable.
Do and don’t
Use a concise title and separate a long body from persistent actions.
Put a long multi-step workflow in a narrow panel when a page is clearer.