Side and bottom sheets that follow the finger, spring to snap points and squash against the edge when thrown, built on Radix Dialog.
DragDrag
5 conversations · 3 open
drawer, lively
Use a drawer for details, editors and filters that belong to the screen behind them: a ticket from an inbox, the filters of a mobile list, a line item of an invoice. The sheet follows the finger 1:1, is thrown to the nearest snap point with the release speed and, past the point it is heading to, squashes against it instead of flying past. The handle pill stretches with the pull and the content cascades in once the sheet arrives. For a short confirmation use a dialog.
pnpm dlx shadcn@latest add @motionkit/drawernpx shadcn@latest add @motionkit/draweryarn dlx shadcn@latest add @motionkit/drawerbunx --bun shadcn@latest add @motionkit/drawerRequires the @motionkit namespace in components.json. See Installation.
import { Drawer } from "@/components/ui/drawer"
;<Drawer.Root preset="bottom">
<Drawer.Trigger>Filters</Drawer.Trigger>
<Drawer.Content>
<Drawer.Handle />
<Drawer.Header>
<Drawer.Title>Filters</Drawer.Title>
<Drawer.Close />
</Drawer.Header>
<Drawer.Body>
<section>Status</section>
<section data-snap="0.9">Date range</section>
</Drawer.Body>
<Drawer.Footer>…</Drawer.Footer>
</Drawer.Content>
</Drawer.Root>Presets: bottom (snap points 40% and 90%), side (a 420 px panel on the right; a bottom sheet
below 640 px unless responsive={false}) and stacked (a side panel that moves 8 px back and
4% smaller while a second drawer is open inside it). Pass Drawer.Portal container to scope the
drawer to a positioned element. Body children with data-snap appear only at that snap point.
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Also accepts all props of Omit<
ComponentProps<typeof DialogPrimitive.Content>,
"asChild" | "forceMount"
>.
Prop
Type
Also accepts all props of Omit<
ComponentProps<"div">,
"onDrag" | "onDragStart" | "onDragEnd" | "onAnimationStart"
>.
bottom)DragDrag
Last 30 days
drawer, lively
stacked)role="dialog", labelled by Drawer.Title, described by
Drawer.Description. Modal drawers trap focus, lock scroll and hide the page from assistive
tech; all of it ends the moment closing starts and focus returns to the trigger.role="slider" over the snap points with aria-valuetext
(snapLabels). Overlay, surface and dimming layers are aria-hidden.dismissible={false} ignores Escape, outside clicks and throw-to-close and hides the close button.| Keys | Action |
|---|---|
| Enter / Space | Opens from the trigger; focus moves into the sheet |
| Tab / Shift+Tab | Cycles focus inside the sheet |
| Escape | Closes and returns focus to the trigger |
| Arrow keys on the handle | Next / previous snap point; past the first it closes |
| Home / End on the handle | Smallest / largest snap point |
Dragging still follows the finger. Opening fades the sheet in already at its snap point, snap changes glide in the fade time with no overshoot, squash or handle stretch, and the content appears at once.
Only transform and opacity animate, driven by motion values (no React render per frame).
Nothing loops; the sheet is measured with one ResizeObserver while open. Third-party:
@radix-ui/react-dialog, @radix-ui/react-focus-scope, aria-hidden, motion.
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Not measured yet · budget 6.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, @radix-ui/react-dialog, @radix-ui/react-focus-scope, motion.
drag, click
Dragging still follows the finger; opening fades the sheet in at its snap point, snap changes glide in the fade time with no overshoot or squash, and content appears at once.
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)