Drawer
A sliding surface for navigation or supporting content.
Installation
Terminal
pnpm dlx shadcn@latest add \
https://react-toolbox.io/r/drawer.json \
https://react-toolbox.io/r/button.json \
https://react-toolbox.io/r/dialog.json \
https://react-toolbox.io/r/input.jsonNew here? Set up your project first. Styles, fonts, and required components are included. The command includes the components used by the examples below.
Usage
Use type="right" to enter from the right. Compose a drawer with responsive Tailwind layout for application navigation.
Composition
Nest DialogRoot inside a drawer. Escape closes the topmost surface and restores focus to its trigger.
Show composition code
tsx
'use client';
import { useState } from 'react';
import { Button } from '@/components/ui/material/button';
import {
DrawerRoot,
DrawerTrigger,
DrawerPortal,
DrawerOverlay,
DrawerContent,
DrawerTitle,
DrawerDescription,
DrawerClose,
} from '@/components/ui/material/drawer';
export default function DrawerComposition() {
return (
<DrawerRoot>
<DrawerTrigger asChild>
<Button raised primary>
Open account drawer
</Button>
</DrawerTrigger>
<DrawerPortal>
<DrawerOverlay />
<DrawerContent side="right" className="gap-6 p-6">
<DrawerTitle>Your account</DrawerTitle>
<DrawerDescription>Manage your profile without leaving this page.</DrawerDescription>
<ProfileDialog />
<DrawerClose asChild>
<Button className="mt-auto">Close account drawer</Button>
</DrawerClose>
</DrawerContent>
</DrawerPortal>
</DrawerRoot>
);
}
import { Input } from '@/components/ui/material/input';
import {
DialogRoot,
DialogTrigger,
DialogPortal,
DialogOverlay,
DialogContent,
DialogBody,
DialogTitle,
DialogDescription,
DialogFooter,
DialogClose,
} from '@/components/ui/material/dialog';
function ProfileDialog() {
const [open, setOpen] = useState(false);
const [name, setName] = useState('Javi');
return (
<div className="space-y-4">
<DialogRoot open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button raised primary>
Edit profile
</Button>
</DialogTrigger>
<DialogPortal>
<DialogOverlay />
<DialogContent>
<DialogBody className="flex flex-col gap-5">
<DialogTitle>Edit profile</DialogTitle>
<DialogDescription>Change the name shown to your teammates.</DialogDescription>
<form
id="profile-composition"
onSubmit={(event) => {
event.preventDefault();
setName(String(new FormData(event.currentTarget).get('name')));
setOpen(false);
}}
>
<Input label="Display name" name="name" defaultValue={name} required />
</form>
</DialogBody>
<DialogFooter>
<DialogClose asChild>
<Button>Cancel</Button>
</DialogClose>
<Button primary type="submit" form="profile-composition">
Save changes
</Button>
</DialogFooter>
</DialogContent>
</DialogPortal>
</DialogRoot>
<p className="text-toolbox-body">
Current name: <output>{name}</output>
</p>
</div>
);
}
State and callbacks
Close Drawer by setting active to false in onOverlayClick or onEscKeyDown. delay preserves the exit animation; it does not close an open drawer.
API reference
Key props and defaults. Full types and inline documentation are included with the source in material/drawer.
Drawer
| Property | Type | Default |
|---|---|---|
active | boolean | false |
insideTree | boolean | false |
onEscKeyDown | (event: KeyboardEvent) => void | — |
onOverlayClick | MouseEventHandler<HTMLDivElement> | — |
type | 'left' | 'right' | 'left' |
withOverlay | boolean | true |
Material guidelines
- Use a temporary drawer over content on small screens and a persistent navigation surface when desktop space permits.
- Navigation rows and subheaders are 48px high with 14px medium labels. Use 8px spacing around groups and dividers, and identify the current destination.