Drawer
A panel that comes in from an edge of the screen, over the page or beside it, for the details of a record, a form or a set of filters the reader opens without leaving their place.
import { useState } from 'react';import { Badge } from '@slotted/react/badge';import { Button } from '@slotted/react/button';import { DescriptionList, DescriptionListDescription, DescriptionListItem, DescriptionListTerm,} from '@slotted/react/description-list';import { Drawer, DrawerBody, DrawerClose, DrawerDescription, DrawerFooter, DrawerHeader, DrawerPanel, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';const DETAILS = [ { term: 'Ship to', value: '1200 Harbor Ave, Seattle, WA' }, { term: 'Payment', value: 'Captured, card ending 4242' }, { term: 'Items', value: '14 cases, 3 products' }, { term: 'Warehouse', value: 'Reno, NV' }, { term: 'Total', value: '$1,240.00' },];export default function DrawerBasic() { const [open, setOpen] = useState(false); return ( <Drawer open={open} onOpenChange={setOpen}> <DrawerTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> View order SO-1182 </Button> )} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>Order SO-1182</DrawerTitle> <DrawerDescription>Contoso Foods, placed on 2 October 2026.</DrawerDescription> <DrawerClose /> </DrawerHeader> <DrawerBody> <Stack gap={4}> <Inline> <Badge tone="accent">Ready to ship</Badge> </Inline> <DescriptionList> {DETAILS.map((detail) => ( <DescriptionListItem key={detail.term}> <DescriptionListTerm>{detail.term}</DescriptionListTerm> <DescriptionListDescription>{detail.value}</DescriptionListDescription> </DescriptionListItem> ))} </DescriptionList> </Stack> </DrawerBody> <DrawerFooter> <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}> Close </Button> <Button onClick={() => setOpen(false)}>Create shipment</Button> </DrawerFooter> </DrawerPanel> </Drawer> );}Installation
The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.
pnpm add @slotted/react @slotted/theme @slotted/themesimport { Drawer, DrawerActions, DrawerBody, DrawerClose, DrawerDefaultsProvider, DrawerDescription, DrawerFooter, DrawerHeader, DrawerPanel, DrawerResizer, DrawerTitle, DrawerTrigger } from '@slotted/react';Sides
side picks the edge the panel comes from: end (the default) for the details of a row, start for navigation, top for a notice about the whole screen, and bottom for a sheet on a phone. start and end are logical, so the drawer changes sides in a right-to-left document.
import { Button } from '@slotted/react/button';import { Drawer, DrawerBody, DrawerClose, DrawerHeader, DrawerPanel, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { Inline } from '@slotted/react/inline';import { Text } from '@slotted/react/typography';const SIDES = [ { side: 'start', label: 'Start', title: 'Warehouses', body: 'Reno, Columbus and Savannah. A panel from the start edge suits navigation between sites.', }, { side: 'end', label: 'End', title: 'Order SO-1182', body: 'Contoso Foods, 14 cases. The end edge is the default and suits the details of a row.', }, { side: 'top', label: 'Top', title: 'Carrier notice', body: 'UPS pickups from Reno run two hours late today. A panel from the top suits a notice that belongs to the whole screen.', }, { side: 'bottom', label: 'Bottom', title: '3 orders selected', body: 'SO-1182, SO-1183 and SO-1184. A sheet from the bottom suits actions on a phone, within reach of the thumb.', },] as const;export default function DrawerSides() { return ( <Inline gap={2}> {SIDES.map((item) => ( <Drawer key={item.side} side={item.side}> <DrawerTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> {item.label} </Button> )} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>{item.title}</DrawerTitle> <DrawerClose /> </DrawerHeader> <DrawerBody> <Text size="sm">{item.body}</Text> </DrawerBody> </DrawerPanel> </Drawer> ))} </Inline> );}Sizes
size sets the panel’s width on start and end to one of five steps: sm (18rem) for one field or a short list, md (24rem, the default) for the details of a record, lg (30rem) for a record with a table, xl (40rem) for two columns, and full for the whole screen. A step wider than the screen is held to the screen’s width. Set --slotted-drawer-extent on the drawer for a width the steps do not hold.
import { Button } from '@slotted/react/button';import { Drawer, DrawerBody, DrawerClose, DrawerHeader, DrawerPanel, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { Inline } from '@slotted/react/inline';import { Text } from '@slotted/react/typography';const SIZES = [ { size: 'sm', body: '18rem. One field or a short list, such as the carrier for a shipment.' }, { size: 'md', body: '24rem, the default. The details of an order or a short form.' }, { size: 'lg', body: '30rem. A record with a table of lines, such as the items of an order.' }, { size: 'xl', body: '40rem. Two columns, such as a customer and their open orders.' }, { size: 'full', body: 'The whole screen. A task that needs every column, such as a pick list.' },] as const;export default function DrawerSizes() { return ( <Inline gap={2}> {SIZES.map((item) => ( <Drawer key={item.size} size={item.size}> <DrawerTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> {item.size} </Button> )} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>Shipment SH-4471</DrawerTitle> <DrawerClose /> </DrawerHeader> <DrawerBody> <Text size="sm">{item.body}</Text> </DrawerBody> </DrawerPanel> </Drawer> ))} </Inline> );}Bottom sheet
On top and bottom the drawer is as tall as its content, up to 4rem short of the screen, and on a wide screen it is at most 40rem wide and centerd. DrawerResizer (slDrawerResizer) draws the grip above the header. On a touch screen the reader can drag the sheet from anywhere on its body; a drag released near the bottom edge, or a fast flick downwards, closes it.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Drawer, DrawerBody, DrawerClose, DrawerDescription, DrawerFooter, DrawerHeader, DrawerPanel, DrawerResizer, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { FieldGroup, FieldGroupContent, FieldGroupLegend } from '@slotted/react/field-group';import { Inline } from '@slotted/react/inline';import { Radio, RadioGroup } from '@slotted/react/radio-group';import { Text } from '@slotted/react/typography';const WINDOWS = [ { value: 'morning', label: 'Thursday 8 October, 8 AM to noon' }, { value: 'afternoon', label: 'Thursday 8 October, 1 to 5 PM' }, { value: 'friday', label: 'Friday 9 October, 8 AM to noon' },];export default function DrawerSheet() { const [open, setOpen] = useState(false); const [pickup, setPickup] = useState('morning'); const [draft, setDraft] = useState(pickup); return ( <Inline align="center" gap={3}> <Text size="sm">Pickup: {WINDOWS.find((window) => window.value === pickup)?.label}</Text> <Drawer open={open} onOpenChange={(next) => { if (next) setDraft(pickup); setOpen(next); }} side="bottom" > <DrawerTrigger render={(props) => ( <Button {...props} size="sm" tone="secondary" variant="outline"> Reschedule </Button> )} /> <DrawerPanel> <DrawerResizer /> <DrawerHeader> <DrawerTitle>Reschedule pickup</DrawerTitle> <DrawerDescription>Shipment SH-4471, UPS Ground from Reno, NV.</DrawerDescription> <DrawerClose /> </DrawerHeader> <DrawerBody> <FieldGroup> <FieldGroupLegend>Pickup window</FieldGroupLegend> <FieldGroupContent> <RadioGroup value={draft} onValueChange={setDraft}> {WINDOWS.map((window) => ( <Radio key={window.value} value={window.value}> {window.label} </Radio> ))} </RadioGroup> </FieldGroupContent> </FieldGroup> </DrawerBody> <DrawerFooter> <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}> Cancel </Button> <Button onClick={() => { setPickup(draft); setOpen(false); }} > Reschedule </Button> </DrawerFooter> </DrawerPanel> </Drawer> </Inline> );}Snap points
snapPoints lists the heights a sheet stops at, as fractions of the screen. On top and bottom the height of the content is a stop as well. A drag is released onto the nearest stop, the arrow keys on the grip move to the next stop, and Home and End move to the first and the last. Start the sheet on a stop with defaultExtent in React or [(extent)] in Angular.
import { Badge } from '@slotted/react/badge';import { Button } from '@slotted/react/button';import { Drawer, DrawerBody, DrawerClose, DrawerDescription, DrawerHeader, DrawerPanel, DrawerResizer, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const SHIPMENTS = [ { id: 'SH-4471', to: 'Contoso Foods, Seattle', status: 'In transit', tone: 'accent' }, { id: 'SH-4472', to: 'Fabrikam Grocers, Portland', status: 'In transit', tone: 'accent' }, { id: 'SH-4473', to: 'Tailspin Market, Boise', status: 'Delayed', tone: 'warning' }, { id: 'SH-4474', to: 'Adventure Works, Denver', status: 'In transit', tone: 'accent' }, { id: 'SH-4475', to: 'Litware Deli, Salt Lake City', status: 'Out for delivery', tone: 'success', }, { id: 'SH-4476', to: 'Proseware Cafe, Spokane', status: 'In transit', tone: 'accent' }, { id: 'SH-4477', to: 'Wingtip Bakery, Eugene', status: 'Delayed', tone: 'warning' }, { id: 'SH-4478', to: 'Coho Winery, Walla Walla', status: 'Out for delivery', tone: 'success' }, { id: 'SH-4479', to: 'Northwind Outlet, Reno', status: 'In transit', tone: 'accent' }, { id: 'SH-4480', to: 'Fourth Coffee, Tacoma', status: 'In transit', tone: 'accent' },] as const;export default function DrawerSnapPoints() { return ( <Drawer defaultExtent={0.4} side="bottom" snapPoints={[0.4, 0.9]}> <DrawerTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Shipments in transit </Button> )} /> <DrawerPanel> <DrawerResizer /> <DrawerHeader> <DrawerTitle>Shipments in transit</DrawerTitle> <DrawerDescription>10 shipments left the Reno warehouse this week.</DrawerDescription> <DrawerClose /> </DrawerHeader> <DrawerBody> <Stack gap={3}> {SHIPMENTS.map((shipment) => ( <Inline key={shipment.id} align="center" gap={3} justify="between"> <Stack gap={0}> <Text size="sm" weight="semibold"> {shipment.id} </Text> <Text size="sm" tone="muted"> {shipment.to} </Text> </Stack> <Badge tone={shipment.tone}>{shipment.status}</Badge> </Inline> ))} </Stack> </DrawerBody> </DrawerPanel> </Drawer> );}Resizing
DrawerResizer (slDrawerResizer) on the panel’s inner edge lets the reader set the width: drag it, or focus it and use the arrow keys, 16 pixels at a time and 64 with Shift. Home and End go to minExtent and maxExtent, Enter collapses the panel to its minimum and restores it, and a double click returns it to its size step. The width is a fraction of the screen: onExtentChange in React and [(extent)] in Angular report it, and undefined means the size step decides.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { DescriptionList, DescriptionListDescription, DescriptionListItem, DescriptionListTerm,} from '@slotted/react/description-list';import { Drawer, DrawerBody, DrawerClose, DrawerDescription, DrawerHeader, DrawerPanel, DrawerResizer, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';const LINES = [ { term: 'Arabica beans, 5 kg', value: '6 cases, $420.00' }, { term: 'Oat milk, 12 × 1 L', value: '4 cases, $192.00' }, { term: 'Paper cups, 16 oz, 1,000 per case', value: '4 cases, $628.00' },];export default function DrawerResize() { const [extent, setExtent] = useState<number | undefined>(undefined); const width = extent === undefined ? 'the md step' : `${Math.round(extent * 100)}% of the window`; return ( <Drawer extent={extent} maxExtent={0.8} minExtent={0.25} onExtentChange={setExtent}> <DrawerTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> View order lines </Button> )} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>Order SO-1182 lines</DrawerTitle> <DrawerDescription>Width: {width}.</DrawerDescription> <DrawerClose /> </DrawerHeader> <DrawerBody> <DescriptionList> {LINES.map((line) => ( <DescriptionListItem key={line.term}> <DescriptionListTerm>{line.term}</DescriptionListTerm> <DescriptionListDescription>{line.value}</DescriptionListDescription> </DescriptionListItem> ))} </DescriptionList> </DrawerBody> <DrawerResizer /> </DrawerPanel> </Drawer> );}Non-modal
modal={false} leaves the page behind interactive: nothing is made inert, the page scroll is not locked, focus can leave the panel, and the panel has no aria-modal. The scrim still covers the page and still takes a pointer press, so add scrimFrom={1} to remove it and outsidePress="none" so working on the page does not close the drawer. Here the reader types a rate from the drawer into the field behind it.
Charged to Contoso Foods on invoice INV-2041.
import { Button } from '@slotted/react/button';import { DescriptionList, DescriptionListDescription, DescriptionListItem, DescriptionListTerm,} from '@slotted/react/description-list';import { Drawer, DrawerBody, DrawerClose, DrawerDescription, DrawerHeader, DrawerPanel, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { TextField } from '@slotted/react/text-field';const RATES = [ { term: 'UPS Ground', value: '$38.40, 3 business days' }, { term: 'FedEx Home Delivery', value: '$41.15, 3 business days' }, { term: 'UPS 2nd Day Air', value: '$96.80, 2 business days' }, { term: 'FedEx Priority Overnight', value: '$184.25, next business day' },];export default function DrawerNonModal() { return ( <Stack gap={4}> <Field> <FieldLabel>Shipping charge</FieldLabel> <TextField inputMode="decimal" placeholder="0.00" /> <FieldDescription>Charged to Contoso Foods on invoice INV-2041.</FieldDescription> </Field> <Inline> <Drawer modal={false} outsidePress="none" scrimFrom={1} size="sm"> <DrawerTrigger render={(props) => ( <Button {...props} size="sm" tone="secondary" variant="outline"> Show carrier rates </Button> )} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>Carrier rates</DrawerTitle> <DrawerDescription>3 packages, 18.4 kg, Reno to Seattle.</DrawerDescription> <DrawerClose /> </DrawerHeader> <DrawerBody> <DescriptionList> {RATES.map((rate) => ( <DescriptionListItem key={rate.term}> <DescriptionListTerm>{rate.term}</DescriptionListTerm> <DescriptionListDescription>{rate.value}</DescriptionListDescription> </DescriptionListItem> ))} </DescriptionList> </DrawerBody> </DrawerPanel> </Drawer> </Inline> </Stack> );}Beside the page
mode="inline" puts the drawer in your own layout instead of over the page: no portal, no scrim, no focus trap, and the panel writes no role. Opening and closing animates the drawer’s own width, so the content beside it reflows through your own layout; here a wrapping flex row, which puts the list under the panel on a narrow screen. The drawer takes no focus when it opens: focus stays on the trigger, which shows and hides the panel.
import { useState } from 'react';import { Badge } from '@slotted/react/badge';import { Button } from '@slotted/react/button';import { Checkbox } from '@slotted/react/checkbox';import { CheckboxGroup } from '@slotted/react/checkbox-group';import { Drawer, DrawerBody, DrawerPanel, DrawerTrigger } from '@slotted/react/drawer';import { FieldGroup, FieldGroupContent, FieldGroupLegend } from '@slotted/react/field-group';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const STATUSES = [ { value: 'processing', label: 'Processing', tone: 'accent' }, { value: 'shipped', label: 'Shipped', tone: 'success' }, { value: 'on-hold', label: 'On hold', tone: 'warning' },] as const;const ORDERS = [ { id: 'SO-1182', customer: 'Contoso Foods', status: 'processing' }, { id: 'SO-1183', customer: 'Fabrikam Grocers', status: 'shipped' }, { id: 'SO-1184', customer: 'Tailspin Market', status: 'on-hold' }, { id: 'SO-1185', customer: 'Adventure Works', status: 'processing' }, { id: 'SO-1186', customer: 'Litware Deli', status: 'shipped' },] as const;export default function DrawerInline() { const [statuses, setStatuses] = useState<readonly string[]>(['processing', 'on-hold']); const shown = ORDERS.filter((order) => statuses.includes(order.status)); return ( <Drawer defaultOpen mode="inline" side="start" size="sm"> <Stack gap={3}> <Inline> <DrawerTrigger render={(props) => ( <Button {...props} size="sm" tone="secondary" variant="outline"> Filters </Button> )} /> </Inline> <div style={{ display: 'flex', flexWrap: 'wrap', minBlockSize: '16rem', border: '1px solid var(--slotted-border-subtle)', borderRadius: 'var(--slotted-radius-lg)', overflow: 'hidden', }} > <DrawerPanel> <DrawerBody> <FieldGroup> <FieldGroupLegend>Status</FieldGroupLegend> <FieldGroupContent> <CheckboxGroup value={statuses} onValueChange={setStatuses}> {STATUSES.map((status) => ( <Checkbox key={status.value} value={status.value}> {status.label} </Checkbox> ))} </CheckboxGroup> </FieldGroupContent> </FieldGroup> </DrawerBody> </DrawerPanel> <Stack gap={3} style={{ flex: '1 1 12rem', padding: 'var(--slotted-space-6)' }}> <Text size="sm" tone="muted"> {shown.length} of {ORDERS.length} orders </Text> {shown.map((order) => { const status = STATUSES.find((item) => item.value === order.status)!; return ( <Inline key={order.id} align="center" gap={3} justify="between"> <Stack gap={0}> <Text size="sm" weight="semibold"> {order.id} </Text> <Text size="sm" tone="muted"> {order.customer} </Text> </Stack> <Badge tone={status.tone}>{status.label}</Badge> </Inline> ); })} </Stack> </div> </Stack> </Drawer> );}Switching between overlay and inline
mode can change while the drawer is open, for example at your own breakpoint or from a pin button. The panel’s content is kept across the switch, so a half-written note survives it. Type a note, pin the drawer beside the order, then unpin it.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { DescriptionList, DescriptionListDescription, DescriptionListItem, DescriptionListTerm,} from '@slotted/react/description-list';import { Drawer, DrawerBody, DrawerClose, DrawerFooter, DrawerHeader, DrawerPanel, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { Field, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Textarea } from '@slotted/react/textarea';const DETAILS = [ { term: 'Customer', value: 'Contoso Foods, Seattle' }, { term: 'Items', value: '14 cases, 3 products' }, { term: 'Warehouse', value: 'Reno, NV' },];export default function DrawerPin() { const [open, setOpen] = useState(false); const [pinned, setPinned] = useState(false); return ( <Drawer mode={pinned ? 'inline' : 'overlay'} open={open} onOpenChange={setOpen} size="sm"> <Stack gap={3}> <Inline> <DrawerTrigger render={(props) => ( <Button {...props} size="sm" tone="secondary" variant="outline"> Notes </Button> )} /> </Inline> <div style={{ display: 'flex', flexWrap: 'wrap', minBlockSize: '18rem', border: '1px solid var(--slotted-border-subtle)', borderRadius: 'var(--slotted-radius-lg)', overflow: 'hidden', }} > <div style={{ flex: '1 1 12rem', padding: 'var(--slotted-space-6)' }}> <DescriptionList> {DETAILS.map((detail) => ( <DescriptionListItem key={detail.term}> <DescriptionListTerm>{detail.term}</DescriptionListTerm> <DescriptionListDescription>{detail.value}</DescriptionListDescription> </DescriptionListItem> ))} </DescriptionList> </div> <DrawerPanel> <DrawerHeader> <DrawerTitle>Notes on SO-1182</DrawerTitle> <DrawerClose /> </DrawerHeader> <DrawerBody> <Field> <FieldLabel>Note for the warehouse</FieldLabel> <Textarea placeholder="Pallet height, dock number, contact on site" /> </Field> </DrawerBody> <DrawerFooter> <Button size="sm" tone="secondary" variant="outline" onClick={() => setPinned(!pinned)} > {pinned ? 'Unpin' : 'Pin beside the order'} </Button> </DrawerFooter> </DrawerPanel> </div> </Stack> </Drawer> );}Long content
The body is the only row that scrolls. The header and the footer stay in place, so the actions are always in reach.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Drawer, DrawerBody, DrawerClose, DrawerDescription, DrawerFooter, DrawerHeader, DrawerPanel, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const EVENTS = [ { at: 'Oct 6, 7:42 AM', what: 'Out for delivery, Seattle, WA' }, { at: 'Oct 6, 5:10 AM', what: 'Arrived at the delivery facility, Seattle, WA' }, { at: 'Oct 5, 11:58 PM', what: 'Departed facility, Portland, OR' }, { at: 'Oct 5, 9:20 PM', what: 'Arrived at facility, Portland, OR' }, { at: 'Oct 5, 2:04 PM', what: 'Departed facility, Medford, OR' }, { at: 'Oct 5, 10:37 AM', what: 'Arrived at facility, Medford, OR' }, { at: 'Oct 4, 11:15 PM', what: 'Departed facility, Sacramento, CA' }, { at: 'Oct 4, 6:48 PM', what: 'Arrived at facility, Sacramento, CA' }, { at: 'Oct 4, 1:30 PM', what: 'Departed facility, Reno, NV' }, { at: 'Oct 4, 9:02 AM', what: 'Processed at the origin facility, Reno, NV' }, { at: 'Oct 3, 6:15 PM', what: 'Picked up from the Northwind warehouse, Reno, NV' }, { at: 'Oct 3, 4:40 PM', what: 'Weighed and labelled: 3 packages, 18.4 kg' }, { at: 'Oct 3, 2:12 PM', what: 'Packed at station 4, Reno, NV' }, { at: 'Oct 3, 11:05 AM', what: 'Picked from aisles 12, 14 and 21' }, { at: 'Oct 2, 4:55 PM', what: 'Released to the warehouse' }, { at: 'Oct 2, 4:31 PM', what: 'Payment captured, card ending 4242' },];export default function DrawerLongContent() { const [open, setOpen] = useState(false); return ( <Drawer open={open} onOpenChange={setOpen}> <DrawerTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Tracking history </Button> )} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>Tracking 1Z999AA10123456784</DrawerTitle> <DrawerDescription>Shipment SH-4471, 16 events since 2 October.</DrawerDescription> <DrawerClose /> </DrawerHeader> <DrawerBody> <Stack gap={4}> {EVENTS.map((event) => ( <Stack key={event.at} gap={0}> <Text size="sm" tone="muted"> {event.at} </Text> <Text size="sm">{event.what}</Text> </Stack> ))} </Stack> </DrawerBody> <DrawerFooter> <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}> Close </Button> <Button>Email to customer</Button> </DrawerFooter> </DrawerPanel> </Drawer> );}A form in a drawer
Put the form in the body and point the footer’s submit button at it with the form attribute, so the actions stay in the footer row. Validate on submit, show each error in its field, and close the drawer only when the data is valid. Copy the saved values into the form when the drawer opens, so Cancel discards the edits.
import { useState, type SubmitEvent } from 'react';import { Button } from '@slotted/react/button';import { Drawer, DrawerBody, DrawerClose, DrawerDescription, DrawerFooter, DrawerHeader, DrawerPanel, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { Field, FieldError, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { Select, SelectContent, SelectItem, type SelectOption, SelectTrigger, SelectValue,} from '@slotted/react/select';import { Stack } from '@slotted/react/stack';import { TextField } from '@slotted/react/text-field';import { Text } from '@slotted/react/typography';const TERMS: SelectOption[] = [ { value: 'due', label: 'Due on receipt' }, { value: 'net-15', label: 'Net 15' }, { value: 'net-30', label: 'Net 30' }, { value: 'net-60', label: 'Net 60' },];const CUSTOMER = { name: 'Contoso Foods', email: 'ap@contoso.com', terms: 'net-30' };const termsLabel = (value: string) => TERMS.find((option) => option.value === value)?.label;function nameError(value: string): string { return value.trim() === '' ? 'Enter the name printed on invoices.' : '';}function emailError(value: string): string { if (value.trim() === '') return 'Enter the address invoices are sent to.'; if (!/^\S+@\S+\.\S+$/.test(value)) return 'Enter an address like ap@contoso.com.'; return '';}export default function DrawerForm() { const [open, setOpen] = useState(false); const [customer, setCustomer] = useState(CUSTOMER); const [name, setName] = useState(customer.name); const [email, setEmail] = useState(customer.email); const [terms, setTerms] = useState(customer.terms); const [submitted, setSubmitted] = useState(false); const errors = submitted ? { name: nameError(name), email: emailError(email) } : null; const submit = (event: SubmitEvent<HTMLFormElement>) => { event.preventDefault(); setSubmitted(true); if (nameError(name) !== '' || emailError(email) !== '') return; setCustomer({ name: name.trim(), email: email.trim(), terms }); setOpen(false); }; return ( <Inline align="center" gap={3}> <Text role="status" size="sm" tone="muted"> {customer.name}, {customer.email}, {termsLabel(customer.terms)} </Text> <Drawer open={open} onOpenChange={(next) => { if (next) { setName(customer.name); setEmail(customer.email); setTerms(customer.terms); setSubmitted(false); } setOpen(next); }} > <DrawerTrigger render={(props) => <Button {...props}>Edit customer</Button>} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>Edit customer</DrawerTitle> <DrawerDescription>Account C-0042, customer since March 2021.</DrawerDescription> <DrawerClose /> </DrawerHeader> <DrawerBody> <form id="edit-customer" noValidate onSubmit={submit}> <Stack gap={4}> <Field required invalid={errors?.name ? true : undefined}> <FieldLabel>Company name</FieldLabel> <TextField autoComplete="organization" value={name} onValueChange={setName} /> <FieldError live="polite" reserve> {errors?.name} </FieldError> </Field> <Field required invalid={errors?.email ? true : undefined}> <FieldLabel>Billing email</FieldLabel> <TextField type="email" value={email} onValueChange={setEmail} /> <FieldError live="polite" reserve> {errors?.email} </FieldError> </Field> <Field> <FieldLabel>Payment terms</FieldLabel> <Select items={TERMS} value={terms} onValueChange={(value) => setTerms(typeof value === 'string' ? value : customer.terms) } > <SelectTrigger> <SelectValue /> </SelectTrigger> <SelectContent> {TERMS.map((option) => ( <SelectItem key={option.value} value={option.value}> {option.label} </SelectItem> ))} </SelectContent> </Select> </Field> </Stack> </form> </DrawerBody> <DrawerFooter> <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}> Cancel </Button> <Button type="submit" form="edit-customer"> Save customer </Button> </DrawerFooter> </DrawerPanel> </Drawer> </Inline> );}Refusing a close with unsaved changes
Every way of closing, from the ✕, Escape, a press outside or the browser’s back gesture, goes through one request: onOpenChange in React and (openChangeRequest) in Angular. Call request.cancel() to keep the drawer open. Here an edited instruction keeps the drawer open and asks in the footer whether to discard the change. Edit the text, then press Escape.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Drawer, DrawerBody, DrawerClose, DrawerDescription, DrawerFooter, DrawerHeader, DrawerPanel, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { Field, FieldLabel } from '@slotted/react/field';import { InlineMessage } from '@slotted/react/inline-message';import { Textarea } from '@slotted/react/textarea';export default function DrawerUnsavedChanges() { const [open, setOpen] = useState(false); const [saved, setSaved] = useState('Leave at the loading dock, door 3.'); const [draft, setDraft] = useState(saved); const [confirming, setConfirming] = useState(false); const close = () => { setConfirming(false); setOpen(false); }; return ( <Drawer open={open} onOpenChange={(next, request) => { if (next) { setDraft(saved); setConfirming(false); } else if (draft !== saved) { request.cancel(); setConfirming(true); return; } setOpen(next); }} > <DrawerTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Delivery instructions </Button> )} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>Delivery instructions</DrawerTitle> <DrawerDescription>Order SO-1182, printed on the packing slip.</DrawerDescription> <DrawerClose /> </DrawerHeader> <DrawerBody> <Field> <FieldLabel>Instructions for the carrier</FieldLabel> <Textarea value={draft} onValueChange={(value) => { setDraft(value); setConfirming(false); }} /> </Field> </DrawerBody> <DrawerFooter> {confirming ? ( <> <InlineMessage live="polite" tone="warning"> Discard your changes to the instructions? </InlineMessage> <Button variant="ghost" tone="secondary" onClick={() => setConfirming(false)}> Keep editing </Button> <Button tone="danger" onClick={close}> Discard </Button> </> ) : ( <> <Button variant="ghost" tone="secondary" onClick={() => (draft === saved ? close() : setConfirming(true))} > Cancel </Button> <Button onClick={() => { setSaved(draft); close(); }} > Save </Button> </> )} </DrawerFooter> </DrawerPanel> </Drawer> );}Loading content
loading marks the body as busy with aria-busy while the header, the ✕ and Escape stay available. Fill the body with skeletons in the shape of the content that is coming, so nothing moves when it arrives.
import { useEffect, useState } from 'react';import { Button } from '@slotted/react/button';import { DescriptionList, DescriptionListDescription, DescriptionListItem, DescriptionListTerm,} from '@slotted/react/description-list';import { Drawer, DrawerBody, DrawerClose, DrawerDescription, DrawerHeader, DrawerPanel, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { Skeleton, SkeletonRegion } from '@slotted/react/skeleton';interface Shipment { carrier: string; tracking: string; packages: string; delivery: string;}const FIELDS: { key: keyof Shipment; term: string; width: string }[] = [ { key: 'carrier', term: 'Carrier', width: '6rem' }, { key: 'tracking', term: 'Tracking number', width: '11rem' }, { key: 'packages', term: 'Packages', width: '8rem' }, { key: 'delivery', term: 'Estimated delivery', width: '9rem' },];export default function DrawerLoading() { const [open, setOpen] = useState(false); const [shipment, setShipment] = useState<Shipment | null>(null); useEffect(() => { if (!open) return; setShipment(null); const timer = setTimeout( () => setShipment({ carrier: 'UPS Ground', tracking: '1Z 999 AA1 01 2345 6784', packages: '3, 18.4 kg in total', delivery: 'Thursday, 8 October', }), 1200, ); return () => clearTimeout(timer); }, [open]); return ( <Drawer open={open} onOpenChange={setOpen} loading={shipment === null}> <DrawerTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Track shipment SH-4471 </Button> )} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>Shipment SH-4471</DrawerTitle> <DrawerDescription>Order SO-1182 for Contoso Foods, Seattle.</DrawerDescription> <DrawerClose /> </DrawerHeader> <DrawerBody> <SkeletonRegion delay={200} loading={shipment === null} messages={{ label: 'Loading shipment' }} minDuration={400} > <DescriptionList> {FIELDS.map((field) => ( <DescriptionListItem key={field.key}> <DescriptionListTerm>{field.term}</DescriptionListTerm> <DescriptionListDescription> {shipment === null ? ( <Skeleton inlineSize={field.width} /> ) : ( shipment[field.key] )} </DescriptionListDescription> </DescriptionListItem> ))} </DescriptionList> </SkeletonRegion> </DrawerBody> </DrawerPanel> </Drawer> );}A drawer over a drawer
A drawer opened from inside another stacks above it. Escape and a press outside close only the top one, and focus returns to the button in the drawer below.
import { Button } from '@slotted/react/button';import { DescriptionList, DescriptionListDescription, DescriptionListItem, DescriptionListTerm,} from '@slotted/react/description-list';import { Drawer, DrawerBody, DrawerClose, DrawerDescription, DrawerHeader, DrawerPanel, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';const ORDER = [ { term: 'Customer', value: 'Contoso Foods' }, { term: 'Items', value: '14 cases, 3 products' }, { term: 'Total', value: '$1,240.00' },];const CUSTOMER = [ { term: 'Account', value: 'C-0042' }, { term: 'Contact', value: 'Ana Ruiz, ap@contoso.com' }, { term: 'Open orders', value: '3, $4,815.50 in total' }, { term: 'Payment terms', value: 'Net 30' },];export default function DrawerNested() { return ( <Drawer> <DrawerTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> View order SO-1182 </Button> )} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>Order SO-1182</DrawerTitle> <DrawerDescription>Placed on 2 October 2026.</DrawerDescription> <DrawerClose /> </DrawerHeader> <DrawerBody> <Stack gap={5}> <DescriptionList> {ORDER.map((detail) => ( <DescriptionListItem key={detail.term}> <DescriptionListTerm>{detail.term}</DescriptionListTerm> <DescriptionListDescription>{detail.value}</DescriptionListDescription> </DescriptionListItem> ))} </DescriptionList> <Inline> <Drawer size="sm"> <DrawerTrigger render={(props) => ( <Button {...props} size="sm" tone="secondary" variant="outline"> View customer </Button> )} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>Contoso Foods</DrawerTitle> <DrawerDescription>Customer since March 2021.</DrawerDescription> <DrawerClose /> </DrawerHeader> <DrawerBody> <DescriptionList> {CUSTOMER.map((detail) => ( <DescriptionListItem key={detail.term}> <DescriptionListTerm>{detail.term}</DescriptionListTerm> <DescriptionListDescription>{detail.value}</DescriptionListDescription> </DescriptionListItem> ))} </DescriptionList> </DrawerBody> </DrawerPanel> </Drawer> </Inline> </Stack> </DrawerBody> </DrawerPanel> </Drawer> );}Defaults for a section
DrawerDefaultsProvider in React and provideDrawerDefaults in Angular set mode, side, size, mount, modal, escape, outsidePress, back and drag once for every drawer under them. A value set on one drawer still wins.
import { Button } from '@slotted/react/button';import { Drawer, DrawerBody, DrawerClose, DrawerDefaultsProvider, DrawerHeader, DrawerPanel, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { Inline } from '@slotted/react/inline';import { Text } from '@slotted/react/typography';export default function DrawerDefaults() { return ( <DrawerDefaultsProvider side="start" size="sm"> <Inline gap={2}> <Drawer> <DrawerTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Warehouses </Button> )} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>Warehouses</DrawerTitle> <DrawerClose /> </DrawerHeader> <DrawerBody> <Text size="sm">From the start edge and small, both from the provider.</Text> </DrawerBody> </DrawerPanel> </Drawer> <Drawer size="lg"> <DrawerTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Carriers </Button> )} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>Carriers</DrawerTitle> <DrawerClose /> </DrawerHeader> <DrawerBody> <Text size="sm"> From the start edge, from the provider, and large because this drawer says so. </Text> </DrawerBody> </DrawerPanel> </Drawer> </Inline> </DrawerDefaultsProvider> );}Order details beside a table
A non-modal drawer shows the record of the row the reader chose and leaves the table usable. The drawer has no trigger: each row’s button sets the order and opens it, and choosing another row while it is open replaces the content in place.
| Order | Customer | Total | Actions |
|---|---|---|---|
| SO-1182 | Contoso Foods | $1,240.00 | |
| SO-1183 | Fabrikam Grocers | $386.50 | |
| SO-1184 | Tailspin Market | $2,075.25 | |
| SO-1185 | Adventure Works | $918.00 |
import { useState } from 'react';import { Badge } from '@slotted/react/badge';import { Button } from '@slotted/react/button';import { DescriptionList, DescriptionListDescription, DescriptionListItem, DescriptionListTerm,} from '@slotted/react/description-list';import { Drawer, DrawerBody, DrawerClose, DrawerDescription, DrawerHeader, DrawerPanel, DrawerTitle,} from '@slotted/react/drawer';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Table, TableBody, TableCell, TableColumnHeader, TableContent, TableHead, TableRow, TableRowHeader,} from '@slotted/react/table';import { VisuallyHidden } from '@slotted/react/visually-hidden';const ORDERS = [ { id: 'SO-1182', customer: 'Contoso Foods', city: 'Seattle, WA', status: 'Ready to ship', tone: 'accent', items: '14 cases, 3 products', total: '$1,240.00', }, { id: 'SO-1183', customer: 'Fabrikam Grocers', city: 'Portland, OR', status: 'Shipped', tone: 'success', items: '6 cases, 2 products', total: '$386.50', }, { id: 'SO-1184', customer: 'Tailspin Market', city: 'Boise, ID', status: 'On hold', tone: 'warning', items: '22 cases, 5 products', total: '$2,075.25', }, { id: 'SO-1185', customer: 'Adventure Works', city: 'Denver, CO', status: 'Ready to ship', tone: 'accent', items: '9 cases, 4 products', total: '$918.00', },] as const;type Order = (typeof ORDERS)[number];export default function DrawerDetailPanel() { const [open, setOpen] = useState(false); const [order, setOrder] = useState<Order>(ORDERS[0]); return ( <> <Table columns={4}> <TableContent> <TableHead> <TableRow> <TableColumnHeader>Order</TableColumnHeader> <TableColumnHeader>Customer</TableColumnHeader> <TableColumnHeader numeric>Total</TableColumnHeader> <TableColumnHeader> <VisuallyHidden>Actions</VisuallyHidden> </TableColumnHeader> </TableRow> </TableHead> <TableBody> {ORDERS.map((row) => ( <TableRow key={row.id} value={row.id}> <TableRowHeader>{row.id}</TableRowHeader> <TableCell>{row.customer}</TableCell> <TableCell numeric>{row.total}</TableCell> <TableCell> <Button aria-label={`View ${row.id}`} size="sm" tone="secondary" variant="ghost" onClick={() => { setOrder(row); setOpen(true); }} > View </Button> </TableCell> </TableRow> ))} </TableBody> </TableContent> </Table> <Drawer modal={false} open={open} onOpenChange={setOpen} outsidePress="none" scrimFrom={1} size="sm" > <DrawerPanel> <DrawerHeader> <DrawerTitle>Order {order.id}</DrawerTitle> <DrawerDescription> {order.customer}, {order.city} </DrawerDescription> <DrawerClose /> </DrawerHeader> <DrawerBody> <Stack gap={4}> <Inline> <Badge tone={order.tone}>{order.status}</Badge> </Inline> <DescriptionList> <DescriptionListItem> <DescriptionListTerm>Items</DescriptionListTerm> <DescriptionListDescription>{order.items}</DescriptionListDescription> </DescriptionListItem> <DescriptionListItem> <DescriptionListTerm>Total</DescriptionListTerm> <DescriptionListDescription>{order.total}</DescriptionListDescription> </DescriptionListItem> </DescriptionList> </Stack> </DrawerBody> </DrawerPanel> </Drawer> </> );}Filtering a list
The filters are a draft while the drawer is open. The apply button shows how many orders the draft matches, Reset returns the draft to every order, and closing the drawer any other way leaves the applied filters as they were.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Checkbox } from '@slotted/react/checkbox';import { CheckboxGroup } from '@slotted/react/checkbox-group';import { Drawer, DrawerBody, DrawerClose, DrawerFooter, DrawerHeader, DrawerPanel, DrawerTitle, DrawerTrigger,} from '@slotted/react/drawer';import { FieldGroup, FieldGroupContent, FieldGroupLegend } from '@slotted/react/field-group';import { Inline } from '@slotted/react/inline';import { Radio, RadioGroup } from '@slotted/react/radio-group';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const ORDERS = [ { id: 'SO-1182', status: 'processing', warehouse: 'RNO' }, { id: 'SO-1183', status: 'shipped', warehouse: 'CMH' }, { id: 'SO-1184', status: 'on-hold', warehouse: 'RNO' }, { id: 'SO-1185', status: 'processing', warehouse: 'SAV' }, { id: 'SO-1186', status: 'shipped', warehouse: 'RNO' }, { id: 'SO-1187', status: 'processing', warehouse: 'CMH' }, { id: 'SO-1188', status: 'on-hold', warehouse: 'SAV' }, { id: 'SO-1189', status: 'processing', warehouse: 'RNO' },];interface Filters { statuses: readonly string[]; warehouse: string;}const ALL: Filters = { statuses: ['processing', 'shipped', 'on-hold'], warehouse: 'any' };const matching = (filters: Filters) => ORDERS.filter( (order) => filters.statuses.includes(order.status) && (filters.warehouse === 'any' || order.warehouse === filters.warehouse), ).length;export default function DrawerFilters() { const [open, setOpen] = useState(false); const [applied, setApplied] = useState<Filters>(ALL); const [draft, setDraft] = useState<Filters>(applied); const count = matching(draft); return ( <Inline align="center" gap={3}> <Text size="sm"> {matching(applied)} of {ORDERS.length} orders </Text> <Drawer open={open} onOpenChange={(next) => { if (next) setDraft(applied); setOpen(next); }} size="sm" > <DrawerTrigger render={(props) => ( <Button {...props} size="sm" tone="secondary" variant="outline"> Filters </Button> )} /> <DrawerPanel> <DrawerHeader> <DrawerTitle>Filter orders</DrawerTitle> <DrawerClose /> </DrawerHeader> <DrawerBody> <Stack gap={6}> <FieldGroup> <FieldGroupLegend>Status</FieldGroupLegend> <FieldGroupContent> <CheckboxGroup value={draft.statuses} onValueChange={(statuses) => setDraft({ ...draft, statuses })} > <Checkbox value="processing">Processing</Checkbox> <Checkbox value="shipped">Shipped</Checkbox> <Checkbox value="on-hold">On hold</Checkbox> </CheckboxGroup> </FieldGroupContent> </FieldGroup> <FieldGroup> <FieldGroupLegend>Warehouse</FieldGroupLegend> <FieldGroupContent> <RadioGroup value={draft.warehouse} onValueChange={(warehouse) => setDraft({ ...draft, warehouse })} > <Radio value="any">Any warehouse</Radio> <Radio value="RNO">Reno, NV</Radio> <Radio value="CMH">Columbus, OH</Radio> <Radio value="SAV">Savannah, GA</Radio> </RadioGroup> </FieldGroupContent> </FieldGroup> </Stack> </DrawerBody> <DrawerFooter> <Button variant="ghost" tone="secondary" onClick={() => setDraft(ALL)}> Reset </Button> <Button onClick={() => { setApplied(draft); setOpen(false); }} > Show {count} orders </Button> </DrawerFooter> </DrawerPanel> </Drawer> </Inline> );}Accessibility
| Key | Effect | Focus |
|---|---|---|
| Tab | moves to the next tabbable element inside the panel, and wraps from the last to the first while modal | the next tabbable element inside the panel |
| Shift+Tab | moves to the previous tabbable element inside the panel, and wraps from the first to the last while modal | the previous tabbable element inside the panel |
| Escape | asks the topmost layer to close, carrying the reason escape; a layer that refuses stops the request reaching the layer beneath it, so one Escape never closes two | returns to the element that held it when the drawer opened |
| ArrowLeft | on the resizer, moves the separator sixteen pixels, or sixty-four with Shift, to the left of the screen, which grows an end panel in a left-to-right document and shrinks it in a mirrored one; with snap points it moves to the adjacent stop | stays on the resizer |
| ArrowRight | on the resizer, moves the separator sixteen pixels, or sixty-four with Shift, to the right of the screen; with snap points it moves to the adjacent stop | stays on the resizer |
| ArrowUp | on the resizer, moves the separator sixteen pixels, or sixty-four with Shift, up the screen, which grows a bottom panel and shrinks a top one; with snap points it moves to the adjacent stop | stays on the resizer |
| ArrowDown | on the resizer, moves the separator sixteen pixels, or sixty-four with Shift, down the screen; with snap points it moves to the adjacent stop | stays on the resizer |
| Home | on the resizer, gives the panel its smallest allowed extent | stays on the resizer |
| End | on the resizer, gives the panel its largest allowed extent | stays on the resizer |
| Enter | on the resizer, collapses the panel to its smallest allowed extent, and from there restores the extent it left. It does not close the drawer, because Escape already means that and a reader pressing Enter on a separator expects the separator to still be there | stays on the resizer |
- Under mode="overlay" the drawer follows the WAI-ARIA dialog (modal) pattern. While it is modal, Tab and Shift+Tab move through the panel and wrap at its ends. Escape closes it, and reaches only the topmost layer, so one press never closes two drawers.
- Under mode="inline" the panel has no role, because a navigation drawer is a navigation landmark and a filter panel is complementary; give it one with render. The trigger has no aria-haspopup there, because an inline drawer is a disclosure, not a popup.
- aria-modal="true" is written only while the drawer is modal, which is the only state in which the page behind is inert. modal is always false under mode="inline".
- The separator follows the WAI-ARIA window splitter pattern. The arrow keys move it in the direction they point, Home and End go to the limits, and Enter collapses the panel to its minimum and then restores it. Enter never closes the drawer; Escape does. The values are percentages, and there is no aria-valuetext, so a screen reader announces 40 rather than 40 per cent.
- A bottom sheet moves under a touch on its body as well as on its separator, and every stop a finger reaches, the height of the content among them, is also reachable with the arrow keys on the separator. It is moved by the page’s own scroll, so a control whose touch-action takes vertical movement keeps its gesture, and a scrolling region at its edge — a message list at its top — passes the pull on to the sheet, unless it sits inside data-drawer-drag="none".
- A closed panel is inert in both modes, so its controls are in neither the tab order nor the accessibility tree.
- Focus moves into an overlay panel when it opens, to the first focusable element unless initialFocus names another, and returns on close to the element that had it before; if that element has left the document, focus goes to its nearest ancestor still in it. An inline drawer moves no focus when it opens, and on close restores focus only when focus is inside the panel or on the page body.
- The ✕ button and the separator are each at least --slotted-target-min across, so both meet the WCAG 2.2 minimum target size of 24 by 24 pixels.
API
Drawer
Props
openboolean- Whether the drawer is open, when you own the state. Update it from onOpenChange.
defaultOpenboolean- Whether an uncontrolled drawer starts open. It is read once, on mount.
extentnumber- The panel’s measure, when you own it: a fraction from 0 to 1 of the screen, or of your layout under mode="inline". undefined means the size step decides. Update it from onExtentChange.
defaultExtentnumber- The measure an uncontrolled drawer starts at. It is read once, on mount.
minExtentnumberDefault0.2- The smallest measure the reader can set, and the separator’s aria-valuemin. A drag released below it asks to close the drawer, with the reason pointer.
maxExtentnumberDefault1- The largest measure the reader can set, and the separator’s aria-valuemax. With snap points, both limits default to the first and the last stop.
snapPointsreadonly number[]- The stops the measure moves between, as fractions. With them an arrow key moves to the next stop, Home and End go to the first and the last, and a drag is released onto the nearest.
mode'overlay' | 'inline'Defaultoverlay- On Drawer, DrawerDefaultsProvideroverlay puts the drawer over the page, in a portal; inline puts it in your own layout. The value can change while the drawer is open, and the panel’s content and the state of its fields are kept across the change.
side'start' | 'end' | 'top' | 'bottom'Defaultend- On Drawer, DrawerDefaultsProviderThe edge the panel comes from. start and end follow the writing direction, so the drawer changes sides in a right-to-left document.
size'sm' | 'md' | 'lg' | 'xl' | 'full' | 'content'Default content on top and bottom, md on start and end- On Drawer, DrawerDefaultsProviderThe panel’s measure at rest: one of the steps sm (18rem), md (24rem), lg (30rem), xl (40rem) and full, or content, which fits what the panel holds, up to 4rem short of the screen. A step wider than the screen is held to it. On a bottom sheet, full is the screen’s height and the footer rests at its bottom.
mount'active' | 'lazy' | 'eager'Defaultactive- On Drawer, DrawerDefaultsProviderWhen an overlay layer is in the document: active only while it is open or closing, lazy from the first open on, and eager from the start, inert while closed. An inline drawer is always in the document.
modalbooleanDefaulttrue- On Drawer, DrawerDefaultsProviderWhether the page behind is inert, its scroll is locked and focus is contained in the panel, and whether the panel carries aria-modal. The scrim is painted either way. Always false under mode="inline".
escape'close' | 'none'Defaultclose- On Drawer, DrawerDefaultsProviderWhether Escape asks to close the drawer. Escape reaches only the topmost layer, and a layer that refuses it does not pass it to the one below.
outsidePress'close' | 'none'Defaultclose- On Drawer, DrawerDefaultsProviderWhether a press outside the layer, the scrim included, asks to close the drawer. It has no effect under mode="inline".
back'close' | 'none'Defaultclose- On Drawer, DrawerDefaultsProviderWhether the browser’s back button or a phone’s back gesture closes a modal drawer instead of leaving the page. The drawer holds one close watcher while it is open where the browser has CloseWatcher, and one history entry elsewhere; a drawer opened without a press shares the way back with the layer opened before it. It has no effect under mode="inline".
drag'panel' | 'resizer'Defaultpanel- On Drawer, DrawerDefaultsProviderWhat a touch moves a bottom sheet by: panel, anywhere on the panel, the sheet and its content scrolling as one; or resizer, the separator only, the body scrolling on its own at the highest stop. A mouse drags the separator, and the sheet settles on the nearest stop.
scrimFromnumberDefault0- While the measure is below this fraction, the scrim is not painted, a press reaches the page, and the root carries data-undimmed. Use it with modal={false} and outsidePress="none".
loadingbooleanDefaultfalse- Marks the body as busy with aria-busy and gives it a minimum height, so the panel does not jump when the content arrives. The header, the ✕, Escape and the separator stay available.
messagesPartial<DrawerMessages>- Words laid over the current language, key by key: close, the name of the ✕. An aria-label on DrawerClose takes precedence.
initialFocus'first' | 'container' | RefObject | falseDefaultfirst- Where focus goes when an overlay drawer opens: first, the first focusable element; container, the panel itself, for content that is read before it is used; a ref; or false, nowhere. An inline drawer moves no focus.
finalFocusRefObject | false- Where focus goes when the drawer closes, as a ref, or false for nowhere. When unset, it returns to the element that had focus when the drawer opened, usually the trigger.
inset'none'- On DrawerBodynone removes the body’s padding, for content that brings its own inset, such as a page or a list that runs to the panel’s edges.
stepnumberDefault16- On DrawerResizerHow far one arrow key moves the separator, in pixels, when there are no snap points.
largeStepnumberDefault64- On DrawerResizerHow far Shift and an arrow key move the separator, in pixels, when there are no snap points.
valuestring- On DrawerCloseThe result of a close from this button, carried on the close request as result.
Events
| Name | Payload | When |
|---|---|---|
onOpenChange | (open: boolean, request: DrawerChangeRequest) | Before the drawer opens or closes, for every way it can: the trigger, the ✕, Escape, a press outside, the back gesture and the handle. The request carries value, previous, reason (pointer, keyboard, dismiss, escape, outsidePress, back or programmatic), result, the source event and cancel(), which keeps the drawer as it is. |
onOpenChangeComplete | (open: boolean) | After the entrance or the exit has ended: true once the drawer is settled open, false once it has left — the moment an application that renders the drawer conditionally removes it, so the exit runs. A drawer mounted open enters from its closed style, as one opened later does. |
onExtentChange | (extent: number | undefined, request: DrawerExtentRequest) | Before the panel’s measure changes, with the reason pointer for a drag or a tap on the grip, keyboard for an arrow key, Home, End or Enter, and programmatic for a change from code. A drag of the separator fires on every pointer move and can report a value below minExtent; a bottom sheet fires once its scroll comes to rest, with the stop it rests on. undefined means the panel is back on its size step, or on the height of its content under size="content". |
onClick, onKeyDown, onPointerDown, on every part | the element’s own events | Whenever the element fires them. Your handler runs first, and preventDefault() in it cancels the drawer’s own behavior for that event. |
Composition
render(props) => ReactNode- On every partReplaces the element a part renders and passes it every attribute the drawer wrote. On DrawerPanel it replaces the panel, not the layer, which is how an inline drawer becomes a nav or an aside.
refRef<DrawerHandle> on Drawer, Ref<HTMLElement> on every part- On Drawer, every partOn a part, the element. On Drawer, a handle with open(), close(result), focus() and panel, the panel element once it is in the document.
containerElement | null- An element to portal this layer into instead of the shared portal root, for an application shell with its own stacking context. setPortalContainer from @slotted/core/portal sets one for the whole document.
useDrawer()() => DrawerContextValue- On inside DrawerReads the drawer inside Drawer: whether it is open, the measure, the ids, the resolved axes and close(reason, result). It throws outside a drawer.
DrawerDefaultsProvider{ mode, side, size, mount, modal, escape, outsidePress, back, drag }- On a subtreeSets these nine axes for every drawer under it. A value set on one drawer still wins.
Parts
| Part | Element | Required | Purpose |
|---|---|---|---|
root | div, in a portal under mode="overlay" | Yes | The layer. Under mode="overlay" it is fixed to the viewport and stacked above the page; under mode="inline" it is a box in your own layout, and its own width or height is what opens and closes. It carries data-ui="drawer", every axis as a data attribute, and data-open, data-loading and data-dragging. |
trigger | button, or the element render returns | No | The control that opens and closes the drawer, rendered where it is written. It carries aria-expanded and aria-controls in both modes, and aria-haspopup="dialog" only under mode="overlay", because an inline drawer is a disclosure. A press on it is never read as a press outside the drawer. |
backdrop | div | No | The scrim behind the panel, painted from --slotted-drawer-scrim under mode="overlay" whether the drawer is modal or not, and not painted while the measure is below scrimFrom. It takes a press like the page would, so a press on it is a press outside the drawer. Set --slotted-drawer-scrim: transparent to paint none. |
panel | div, or the element render returns | Yes | The surface, aligned to side. Under mode="overlay" it carries role="dialog", and aria-modal="true" while modal; under mode="inline" it has no role, so use render to make it a nav or an aside. Its rows are the header, the body and the footer, and only the body scrolls. |
resizer | div with role="separator" | No | The separator the reader drags, or focuses and moves with the keyboard, to resize the panel. Rendering it is what makes the drawer resizable. It carries role="separator", tabindex="0", aria-orientation, aria-valuenow, aria-valuemin and aria-valuemax as percentages, aria-controls naming the panel and aria-labelledby naming the title. On start and end it sits on the panel’s inner edge; on top and bottom it is the grip above the header. |
line | span | Yes | A hairline on each side of the grip on start and end, which runs the whole edge under the pointer, under focus and during a drag. It is not drawn on top and bottom. |
grip | span[aria-hidden] | Yes | The mark the pointer aims at: a dot grid on start and end, and a pill above the header on top and bottom. It is hidden from assistive technology, because the separator around it is already named and valued. |
header | header, or the element render returns | No | Lays out the title and the description in one column, the actions in a second when they are rendered, and the close button in the last, so a title that wraps grows the row instead of moving the buttons. |
actions | div, or the element render returns | No | One or two actions beside the title, such as icon buttons for history and a new conversation, on the title’s row between the title and the close button. The buttons keep the size you give them. |
title | h2, or the element render returns | No | The visible name of the drawer. The panel and the separator point at it with aria-labelledby, and only while it is rendered. |
description | p, or the element render returns | No | The sentence under the title. The panel points at it with aria-describedby while it is rendered. |
body | div, or the element render returns | No | The row that scrolls, and the row that carries aria-busy while loading is set. A wheel that reaches its end does not scroll the page behind. inset="none" removes its padding, for content that brings its own, such as a list that runs to the panel’s edges. |
footer | footer, or the element render returns | No | The actions, in a wrapping row aligned to the end, on a sunken surface with a rule above it. |
close | button | No | The ✕ button. Its target is at least --slotted-target-min in both directions. It closes the drawer with the reason dismiss, and its value is the result of that close. |
Theming
Each token is a CSS custom property: set it in a theme, or on any element to retune every drawer inside it.
Drawer tokens
| Token | Default |
|---|---|
--slotted-drawer-backdrop-filter | none |
--slotted-drawer-body-color | var(--slotted-text, CanvasText) |
--slotted-drawer-border-color | var(--slotted-border-subtle, ButtonBorder) |
--slotted-drawer-close-active-background | var(--slotted-tone-secondary-subtle-active) |
--slotted-drawer-close-color | var(--slotted-text-muted, GrayText) |
--slotted-drawer-close-hover-background | var(--slotted-tone-secondary-subtle-hover) |
--slotted-drawer-color | var(--slotted-text, CanvasText) |
--slotted-drawer-description-color | var(--slotted-text-muted, GrayText) |
--slotted-drawer-extent | var(--_step) |
--slotted-drawer-extent-lg | 30rem |
--slotted-drawer-extent-md | 24rem |
--slotted-drawer-extent-sm | 18rem |
--slotted-drawer-extent-xl | 40rem |
--slotted-drawer-footer-backdrop-filter | none |
--slotted-drawer-footer-surface | var(--slotted-surface-sunken, Canvas) |
--slotted-drawer-header-backdrop-filter | none |
--slotted-drawer-header-surface | var(--slotted-drawer-surface, var(--slotted-surface-raised, Canvas)) |
--slotted-drawer-radius | var(--_radius) |
--slotted-drawer-radius-expanded | 0px |
--slotted-drawer-resizer-line-active-color | var(--slotted-text-muted, ButtonText) |
--slotted-drawer-resizer-line-color | var(--slotted-border-strong, ButtonBorder) |
--slotted-drawer-rule-color | var(--slotted-border-subtle, ButtonBorder) |
--slotted-drawer-scrim | var(--slotted-scrim, Canvas) |
--slotted-drawer-scrim-backdrop-filter | none |
--slotted-drawer-sheet-dim | 1 |
--slotted-drawer-sheet-floor | 100% |
--slotted-drawer-sheet-height | 0px |
--slotted-drawer-sheet-inline-size | var(--slotted-drawer-extent-xl, 40rem) |
--slotted-drawer-sheet-travel | 0px |
--slotted-drawer-slide-duration | var(--slotted-duration-long) |
--slotted-drawer-slide-easing | var(--slotted-easing-standard) |
--slotted-drawer-slide-exit-duration | var(--slotted-duration-medium) |
--slotted-drawer-slide-exit-easing | var(--slotted-easing-exit) |
--slotted-drawer-surface | var(--slotted-surface-raised, Canvas) |
--slotted-drawer-title-color | var(--slotted-text, CanvasText) |
--slotted-drawer-title-font-family | var( --slotted-font-family-heading, var(--slotted-font-family-sans, ui-sans-serif, system-ui, sans-serif) ) |
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-action-gap | comfortable 8px · compact 6px · dense 4px |
--slotted-border-strong | Set per scheme by the theme |
--slotted-border-subtle | Set per scheme by the theme |
--slotted-border-width-thick | 2px |
--slotted-border-width-thin | 1px |
--slotted-control-font-family | var(--slotted-font-family-sans) |
--slotted-control-icon-size-md | comfortable 16px · compact 14px · dense 13px |
--slotted-control-inner-size-md | comfortable 24px · compact 20px · dense 18px |
--slotted-control-radius | var(--slotted-radius-sm) |
--slotted-control-transition-duration | var(--slotted-duration-short) |
--slotted-control-transition-easing | var(--slotted-easing-standard) |
--slotted-duration-instant | 1ms |
--slotted-duration-long | 320ms |
--slotted-duration-medium | 200ms |
--slotted-duration-short | 120ms |
--slotted-easing-enter | cubic-bezier(0.05, 0.7, 0.1, 1) |
--slotted-easing-exit | cubic-bezier(0.3, 0, 0.8, 0.15) |
--slotted-easing-standard | cubic-bezier(0.2, 0, 0, 1) |
--slotted-focus-ring-color | Set per scheme by the theme |
--slotted-focus-ring-offset | var(--slotted-border-width-thick) |
--slotted-focus-ring-width | var(--slotted-border-width-thick) |
--slotted-font-family-heading | var(--slotted-font-family-sans) |
--slotted-font-family-sans | 'Geist Variable', ui-sans-serif, system-ui, sans-serif |
--slotted-font-size-lg | 1rem |
--slotted-font-size-md | 0.875rem |
--slotted-font-size-xl | 1.125rem |
--slotted-font-weight-semibold | 600 |
--slotted-line-height-lg | 1.5 |
--slotted-line-height-md | 1.5 |
--slotted-radius-full | 9999px |
--slotted-radius-lg | 8px |
--slotted-radius-sm | 4px |
--slotted-scrim | Set per scheme by the theme |
--slotted-shadow-lg | Set per scheme by the theme |
--slotted-space-11 | 3rem |
--slotted-space-12 | 4rem |
--slotted-space-2 | 0.25rem |
--slotted-space-4 | 0.5rem |
--slotted-space-5 | 0.75rem |
--slotted-space-6 | 1rem |
--slotted-space-7 | 1.25rem |
--slotted-space-8 | 1.5rem |
--slotted-space-9 | 2rem |
--slotted-surface-raised | Set per scheme by the theme |
--slotted-surface-sunken | Set per scheme by the theme |
--slotted-target-comfortable | 44px |
--slotted-target-min | 24px |
--slotted-text | Set per scheme by the theme |
--slotted-text-muted | Set per scheme by the theme |
--slotted-tone-secondary-subtle-active | Set per scheme by the theme |
--slotted-tone-secondary-subtle-hover | Set per scheme by the theme |
--slotted-z-index-overlay | 1000 |