Drawer
A panel that rises from the bottom of the screen and is dragged back down to dismiss it: a few actions or a short form on a phone. It holds the focus like a dialog, and can rest at several heights. For a panel at the side of a wide screen, use a sheet.
Install
npx shadcn@latest add https://thrumui.dev/r/drawer.jsonAdds components/ui/drawer.tsx and installs @base-ui/react@1.9.0. Nothing else in your project changes.
import { Drawer } from "@/components/ui/drawer";Props
| Prop | Type | Default | Description |
|---|---|---|---|
Drawer: open | boolean | – | Whether it is open, when the parent holds the state. Use it with onOpenChange. |
Drawer: defaultOpen | boolean | Default false | Whether it starts open, when the drawer holds its own state. |
Drawer: onOpenChange | (open: boolean) => void | – | Called when the drawer opens or closes, whatever caused it: a button, Escape, the veil or a drag. |
Drawer: snapPoints | (number | string)[] | – | Heights the drawer rests at. 0 to 1 is a share of the screen's height, a larger number is pixels, and a string is px or rem. Without it the drawer is open or closed. |
Drawer: snapPoint | number | string | null | – | The snap point it rests at, when the parent holds it. Use it with onSnapPointChange. |
Drawer: defaultSnapPoint | number | string | null | – | The snap point it opens at. The default is the first one. |
Drawer: onSnapPointChange | (snapPoint) => void | – | Called when a drag lands on another snap point. |
Drawer: snapToSequentialPoints | boolean | Default false | A fast flick moves one snap point at a time instead of skipping to the far one. |
Drawer: disablePointerDismissal | boolean | Default false | A press on the veil no longer closes the drawer. Dragging, Escape and DrawerClose still do. |
Drawer: sound | boolean | Default true | Play a soft sound on opening and on closing, if the visitor has sound on. |
DrawerTrigger | button props | – | The button that opens the drawer. Style it with buttonClass(). |
DrawerContent: className | string | – | Extra classes for the panel. It is as wide as the screen up to 512 pixels, and at most 85% of the screen tall. |
DrawerHandle | ComponentProps<"div"> | – | The grab bar at the top, 40 by 4 pixels. It is a hint, hidden from screen readers. |
DrawerHeader, DrawerFooter | ComponentProps<"div"> | – | Layout for the title block and for the actions. The footer stacks full-width buttons. |
DrawerTitle | heading props | – | The drawer's name, announced when it opens. Every drawer needs one. |
DrawerDescription | paragraph props | – | The explanation under the title, read after the name. |
DrawerClose | button props | – | A button that closes the drawer. Its own onClick runs first. Every drawer needs one. |
Motion and sound
Motion
- The drawer slides up from the bottom edge over 200 ms while the veil fades in.
- While it is dragged it follows the finger with no delay, and the veil fades with the distance.
- Let go past the halfway point, or with a quick flick, and it slides out. Otherwise it slides back to its place or to the nearest snap point.
- Reduced motion: the drawer and the veil appear and leave at once. Dragging still moves it.
Sound
- A soft rising tone when the drawer opens.
- A soft falling tone when it closes, whichever way it was closed.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- It follows the WAI-ARIA dialog pattern: role dialog, modal, named by its title and described by its description.
- Dragging is never the only way out: Escape, a press on the veil and DrawerClose all close it. Keep a DrawerClose in every drawer.
- While it is open the rest of the page cannot be reached by pointer, keyboard or screen reader, and the page behind does not scroll.
- Long content scrolls inside the drawer. A touch drag scrolls first and moves the drawer only once the content is at its top.
- A mouse drag anywhere on the drawer moves it, so text in it is not selected by dragging. Fields and sliders keep their own drag.
- The top corners follow the theme's radius, and the bottom padding clears a phone's home indicator.
- Under a glass material the drawer is translucent. Its tint keeps the text at 4.5 to 1 over any page.
| Keys | Action |
|---|---|
| Enter / Space | On the trigger: open the drawer. Focus moves to the drawer itself, so its title is read first. |
| Tab / Shift Tab | Move through the controls inside the drawer. Focus cannot leave it. |
| Esc | Close the drawer. Focus returns to the trigger. |
Source
"use client";
import type { ComponentProps } from "react";
import { Drawer as DrawerPrimitive } from "@base-ui/react/drawer";
import { cn } from "@/lib/utils";
import { play } from "@/lib/thrum-sound";
export type DrawerProps = DrawerPrimitive.Root.Props & {
/** Play a soft sound when the drawer opens and when it closes, if the visitor has sound on. */
sound?: boolean;
};
/**
* A panel that rises from the bottom of the screen and can be dragged back down: actions and short forms on a phone.
* It holds the focus like a dialog. `snapPoints` lets it rest at several heights. `Drawer` holds the state,
* `DrawerTrigger` opens it, `DrawerContent` is the panel.
*/
export function Drawer({ sound = true, onOpenChange, ...props }: DrawerProps) {
return (
<DrawerPrimitive.Root
onOpenChange={(open, details) => {
if (sound) play(open ? "open" : "close");
onOpenChange?.(open, details);
}}
{...props}
/>
);
}
/** The button that opens the drawer. Style it with `buttonClass()` or pass a `Button` through `render`. */
export function DrawerTrigger(props: DrawerPrimitive.Trigger.Props) {
return <DrawerPrimitive.Trigger data-slot="drawer-trigger" {...props} />;
}
/** A button that closes the drawer. Every drawer needs one: dragging is not possible for everyone. */
export function DrawerClose(props: DrawerPrimitive.Close.Props) {
return <DrawerPrimitive.Close data-slot="drawer-close" {...props} />;
}
/**
* The panel itself, with the veil behind it. It is as tall as its content, up to 85% of the screen, then it scrolls.
* It follows the finger while it is dragged, and the veil fades with it. It is a floating surface, so it turns to
* glass when the page's material asks for it.
*/
export function DrawerContent({ className, children, ...props }: DrawerPrimitive.Popup.Props) {
return (
<DrawerPrimitive.Portal>
<DrawerPrimitive.Backdrop
data-slot="drawer-backdrop"
className="fixed inset-0 z-50 bg-background/70 opacity-[calc(1-var(--drawer-swipe-progress))] transition-opacity duration-200 ease-out data-ending-style:opacity-0 data-starting-style:opacity-0 data-swiping:transition-none motion-reduce:transition-none"
/>
<DrawerPrimitive.Viewport data-slot="drawer-viewport" className="fixed inset-0 z-50 flex items-end justify-center">
<DrawerPrimitive.Popup
data-slot="drawer"
data-surface="floating"
className={cn(
"flex max-h-[85dvh] w-full max-w-lg flex-col gap-4 overflow-y-auto overscroll-contain rounded-t-xl border border-b-0 bg-popover px-5 pt-3 pb-[calc(1.25rem+env(safe-area-inset-bottom,0px))] text-popover-foreground outline-none",
// The library reads the drawer's position from `transform`, so the slide uses it rather than `translate`.
"[transform:translateY(calc(var(--drawer-snap-point-offset)+var(--drawer-swipe-movement-y)))] transition-transform duration-200 ease-out",
"data-ending-style:[transform:translateY(100%)] data-starting-style:[transform:translateY(100%)] data-swiping:select-none motion-reduce:transition-none",
// A solid shadow carries the surface on below the screen edge, so pulling the drawer up past its place shows no gap.
"shadow-[0_3rem_0_0_var(--popover)]",
className,
)}
{...props}
>
{children}
</DrawerPrimitive.Popup>
</DrawerPrimitive.Viewport>
</DrawerPrimitive.Portal>
);
}
/** The grab bar at the top. It is a hint for the hand, not a control: the whole drawer can be dragged. */
export function DrawerHandle({ className, ...props }: ComponentProps<"div">) {
return <div data-slot="drawer-handle" aria-hidden="true" className={cn("mx-auto h-1 w-10 flex-none rounded-[calc(var(--radius)*9999)] bg-muted-foreground/50", className)} {...props} />;
}
/** Title and description. */
export function DrawerHeader({ className, ...props }: ComponentProps<"div">) {
return <div data-slot="drawer-header" className={cn("grid gap-1.5", className)} {...props} />;
}
/** The drawer's name: every drawer needs one. Screen readers announce it when the drawer opens. */
export function DrawerTitle({ className, ...props }: DrawerPrimitive.Title.Props) {
return <DrawerPrimitive.Title data-slot="drawer-title" className={cn("text-base leading-5 font-semibold", className)} {...props} />;
}
export function DrawerDescription({ className, ...props }: DrawerPrimitive.Description.Props) {
return <DrawerPrimitive.Description data-slot="drawer-description" className={cn("text-sm text-muted-foreground", className)} {...props} />;
}
/** The actions, stacked and as wide as the drawer, with the main action on top. */
export function DrawerFooter({ className, ...props }: ComponentProps<"div">) {
return <div data-slot="drawer-footer" className={cn("mt-auto flex flex-col gap-2", className)} {...props} />;
}Files and dependencies
- Adds
components/ui/drawer.tsx- Packages
@base-ui/react@1.9.0- Brings along
- Sound engine
Changelog
- 1.0.0 · 2026-12-03First release.