How it works
During a drag the offset is written straight to CSS variables, so no React render happens per frame. On release the position is projected 220ms ahead with the release velocity and the nearest snap point wins; a flick always moves at least one point. Past the top edge the drag resists with a rubber-band curve. The second-highest point to full drives --ds-snap-p, which scales the background to 0.93, rounds its corners and dims a scrim.
Use it for
- Map, media or list screens on phones where the content behind should stay visible.
- Progressive detail: a peek summary that expands into the full list.
Look elsewhere when
- A short choice or confirmation: use a simple bottom sheet or dialog.
- Wide desktop layouts: use a side panel.
Usage
import { useState } from 'react'
import { SnapDrawer } from './SnapDrawer.jsx'
export function MapScreen() {
const [open, setOpen] = useState(true)
return (
<SnapDrawer
open={open}
onOpenChange={setOpen}
snapPoints={[0.22, 0.55, 0.92]}
background={<Map />}
header={<h2>Nearby</h2>}
>
<PlaceList />
</SnapDrawer>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
open | boolean | true | Whether the drawer is shown. |
onOpenChange | (open: boolean) => void | — | Called when it is swiped away or Escape is pressed. |
snapPoints | number[] | [0.22, 0.55, 0.92] | Visible heights as fractions of the frame, lowest first. |
snap / defaultSnap / onSnapChange | number | defaultSnap 1 | The current snap index, controlled or not. |
snapLabels | string[] | ['Peek', 'Half', 'Full'] | Spoken names of the snap points. |
background | ReactNode | — | The screen behind the drawer; it scales back as the drawer reaches full. |
header | ReactNode | — | Always-visible top part; it is also a drag area. |
children | ReactNode | — | The body; it scrolls only at full height. |
dismissible | boolean | true | Allow swiping below the lowest point to close. |
scaleBackground | boolean | true | Push the background back near full height. |
contained | boolean | false | Fill the nearest positioned ancestor instead of the viewport. |
label / handleLabel | string | handleLabel 'Resize sheet' | Accessible names of the drawer (defaults to the header) and its handle. |
Accessibility
- The drawer is role dialog (modal only at full height) labelled by its header.
- The handle is a vertical role slider with aria-valuetext naming the snap point; Up and Down move between points, Home and End jump, Enter cycles.
- Escape closes it when dismissible; a closed drawer is inert and aria-hidden.
- Drag areas use touch-action none, while the body scrolls natively at full height; the handle is 88 by 26 px plus the header area.
- With reduced motion snapping is instant and only the scrim fades.
Motion
Snap 520ms cubic-bezier(0.32, 0.72, 0, 1); velocity projection 220ms; rubber band (1 − 1/(0.55·d/D + 1))·D with D = 15% of the frame; background scale 1 → 0.93, radius 0 → 18px, scrim 0 → 30%.
Add it to your project
Pro members copy a prompt and their coding agent installs the source, the same way as the free components.
SnapDrawer.jsxsnap-drawer.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.



