Root Props
| Prop | Type | Default |
|---|---|---|
defaultOpen | boolean | false |
| Controls whether the drawer is default open. | ||
open | boolean | — |
| Controls whether the drawer is open. When provided, the component becomes controlled. | ||
onChangeOpen | (value: boolean) => void | — |
| Callback fired when the drawer's open state changes. Receives the new state as a boolean. | ||
position | DrawerPosition | 'end' |
Defines from which side of the screen the drawer appears. start and end follow the writing direction, like CSS logical properties: in right-to-left text end is the left side. | ||
children | ReactNode | — |
| The content to display inside the drawer. Typically, includes navigation, settings, or forms. | ||
Child Parts
DrawerTrigger
Open action for the drawer. Sets aria-haspopup="dialog" and aria-expanded.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | — |
If true, renders the trigger as a child element using Slot. This enables custom wrappers (e.g., <a>, <div>) to inherit drawer-opening behavior. | ||
ref | Ref<HTMLButtonElement> | — |
| Ref forwarded to the native button or slotted element. Useful for focus management or integrations. | ||
Also accepts all <button> attributes.
DrawerContent
The native modal <dialog>, positioned by the root position.
| Prop | Type | Default |
|---|---|---|
ref | Ref<HTMLDialogElement> | — |
Ref forwarded to the native <dialog> element. Useful for measuring, focusing, or animation hooks. | ||
shadowed | boolean | — |
| Adds a shadow to the drawer panel for depth and separation. | ||
blurred | boolean | true |
| Blurs the page behind the drawer. | ||
overlay | boolean | true |
| Dims the page behind the drawer. When false, the page stays visible and the drawer stays modal. | ||
closedBy | ModalDialogClosedBy | 'any' |
Which user actions close the drawer, like the native closedby attribute: any a backdrop click, a touch swipe toward its edge or Escape, closerequest only Escape, none neither. | ||
fullWidth | boolean | — |
| Makes the drawer stretch to fill the full width of its parent container. | ||
fullHeight | boolean | — |
| Makes the drawer stretch to fill the full height of its parent container. | ||
Also accepts all <dialog> attributes.
- It sets no
idoraria-labelledbyitself: name it witharia-labelledbypointing to your heading'sid, or witharia-label.onCancelandonCloserun after the internal handlers.refpoints to the<dialog>element. blurred(defaulttrue) blurs the page behind the drawer.overlay(defaulttrue) dims the page;falsemakes the::backdroptransparent while the drawer stays modal.shadowedadds the surface shadow;fullWidthandfullHeightstretch the panel.closedBysets which user actions close the drawer, like the nativeclosedbyattribute:'any'(a backdrop click, a touch swipe toward its edge, orEscape, the default),'closerequest'(Escapeonly), or'none'.- Closes on submit of a
<form method="dialog">inside it, also withclosedBy='none'. The close goes throughonChangeOpen(false), and the submit button'svaluebecomes the dialog'sreturnValue. - With
closedBy='any', a touch swipe toward the drawer's edge drags it and closes it past half its size or on a flick. Mouse drags are left for text selection. - Stays mounted only while open and while the close transition plays.
DrawerClose
Closes the drawer when clicked. It has no styles, icon, or default aria-label: render your own button inside it with asChild and label it.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | — |
If true, renders the close action as its child element using Slot, so any button of your own closes the drawer. | ||
ref | Ref<HTMLButtonElement> | — |
| Ref forwarded to the underlying button. | ||
Also accepts all <button> attributes.
- The close goes through
onChangeOpen(false), so the close transition plays and a controlled parent can keep the drawer open. - Use it for a standalone close button, such as the X in a header. For buttons that answer the drawer (Cancel, Confirm, a
returnValue), use a<form method="dialog">. WithoutasChildit renderstype="button", so it also works inside a form of your own without submitting it; withasChildgive your own buttontype="button".
minimal-composition.tsx · 43 lines
import { useId, type CSSProperties } from 'react';
import {
Button,
Drawer,
DrawerClose,
DrawerContent,
DrawerTrigger,
Heading,
Icon,
IconButton,
Text,
} from '@vega-ui/react';Hooks
useDrawerContext
Returns { open, changeOpen, position } for advanced wrappers and custom controls.
Types
DrawerPropsDrawerTriggerPropsDrawerContentPropsDrawerCloseProps
State Model
- Open state can be controlled with
openor uncontrolled withdefaultOpen. - Every close request (backdrop click, swipe,
Escape,DrawerCloseclick,<form method="dialog">submit) goes throughonChangeOpen(false); a controlled drawer stays open untilopenbecomesfalse. closedBy='none'onDrawerContentdisables backdrop click, swipe, andEscape; close it with a button in a<form method="dialog">or by changingopen.positionuses logical sides that follow the writing direction:'top-start','top','top-end','end-start','end','end-end','bottom-start','bottom','bottom-end','start-start','start','start-end'. In right-to-left textendis the left side.- Page scroll is locked while the drawer is open.
- The drawer is always modal;
overlay={false}only hides the dimming.