Cómo funciona
A modal side panel: 18px / 600 title with a round close button, 14px body, 24px content padding and right-aligned pill buttons in the footer. It floats 8px in from one edge at full height with 24px corners, a hairline ring and a soft large shadow, and has no dividers: the content area hides its scrollbar and fades 16px on the side with more content. While open, focus is trapped, siblings are inert and page scrolling is locked; Escape stays with the drawer. It portals to body by default; contained keeps it inside its positioned ancestor. The CSS includes 40px pill buttons (ds-drawer__btn: --primary ink, --secondary grey, --danger).
Úsalo para
- Viewing one record on desktop: click a row and the detail slides in while the list stays in place.
- Longer forms on desktop, such as creating or editing a record, without leaving the page.
- Phones under 768px: use a bottom sheet instead; the open and close props are the same.
- Filter panels with too many conditions for one row.
Busca otra opción cuando
- On phones: a side drawer covers almost the whole screen and the close button is hard to reach.
- A few items or one confirmation sentence: use a dialog.
- Opening a drawer or dialog inside a drawer: change the content in the same drawer instead.
- A panel that must stay beside the main content: that is a page column; a drawer is modal and blocks what is behind it.
Uso
import { useState } from 'react'
import { Drawer } from './Drawer.jsx'
export function ProductRow({ product }) {
const [open, setOpen] = useState(false)
return (
<>
<button onClick={() => setOpen(true)}>Details</button>
<Drawer
open={open}
onClose={() => setOpen(false)}
title={product.name}
width={520}
footer={
<>
<button className="ds-drawer__btn ds-drawer__btn--secondary" onClick={() => setOpen(false)}>
Close
</button>
<button className="ds-drawer__btn ds-drawer__btn--primary" onClick={() => addToCart(product.id)}>
Add to cart
</button>
</>
}
>
<ProductDetail product={product} />
</Drawer>
</>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
open | boolean | — | Whether the drawer is open. |
onClose | () => void | — | Asks to close (close button, mask click or Escape). You set open to false. |
title | ReactNode | — | Title, also the accessible name (aria-labelledby). Without one, pass aria-label yourself. |
children | ReactNode | — | Content. Overflow scrolls inside the content area; header and footer stay put. |
footer | ReactNode | — | Fixed action area at the bottom, pill buttons right-aligned. Without it there is no footer. |
side | 'right' | 'left' | 'right' | Which edge it slides in from. |
width | number | string | 400 | Width: a number is px, or any CSS length. 400 / 520 / 720 suggested. At least 48px of mask (plus the 8px gap) stays when the container is narrow. |
closable | boolean | true | Shows the close button at the top right. |
maskClosable | boolean | true | Whether clicking the mask closes it. |
closeOnEsc | boolean | true | Whether Escape closes it. |
busy | boolean | false | While submitting: the close button, mask and Escape do nothing, and the panel gets aria-busy. |
contained | boolean | false | Limits it to the nearest positioned ancestor (absolute). By default it portals to body and fills the viewport. |
initialFocus | RefObject | — | Element to focus after opening. Defaults to the drawer itself. |
labels | object | — | Replaces built-in text (close). Shallow-merged over the English defaults. |
...rest | HTMLAttributes | — | className and other attributes go to the panel (the role="dialog" element), such as aria-describedby and style. |
Accesibilidad
- The panel is role="dialog" with aria-modal="true" and is named by its title through aria-labelledby.
- On open, focus moves into the drawer (or to initialFocus) and Tab cycles inside; on close it returns to the opener.
- Siblings are inert while open, and page scrolling is locked unless contained.
- Escape and a mask click close it, except while busy; Escape is not passed on, and Escape during IME composition does not close it.
- The close button is a real button with an accessible name, a 32px circle with a 44px hit area; footer pill buttons are 40px with a 44px hit area.
- Scrollable content is keyboard-focusable so arrow keys scroll it; reduced motion fades instead of sliding.
Movimiento
Enter: the panel slides in from beyond the edge over 320ms ease-out (fast, then a long settle) and the mask (dimmed, 6px blur) fades in over 240ms. Exit is faster: 200ms ease-in for both, then it unmounts. Only transform and opacity animate; reduced motion fades instead of sliding.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
Drawer.jsxdrawer.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

