Skip to content
Thrum

Sheet

A panel that slides in from an edge of the screen and holds the focus until it is closed: filters, the details of a record, a phone's navigation. It keeps the page in view behind a veil. For a short question use a dialog; for a panel a phone user drags away, a drawer.

Install

npx shadcn@latest add https://thrumui.dev/r/sheet.json

Adds components/ui/sheet.tsx and installs @base-ui/react@1.9.0. Nothing else in your project changes.

import { Sheet } from "@/components/ui/sheet";

Automatically installs icon x from the icon set.

Props

PropTypeDefaultDescription
Sheet: openboolean–Whether it is open, when the parent holds the state. Use it with onOpenChange.
Sheet: defaultOpenbooleanDefault falseWhether it starts open, when the sheet holds its own state.
Sheet: onOpenChange(open: boolean) => void–Called when the sheet opens or closes, whatever caused it.
Sheet: soundbooleanDefault truePlay a soft sound on opening and on closing, if the visitor has sound on.
SheetTriggerbutton props–The button that opens the sheet. Style it with buttonClass().
SheetContent: side"top" | "right" | "bottom" | "left"Default "right"The edge of the screen the sheet is attached to and slides in from.
SheetContent: size"sm" | "md" | "lg" | "full"Default "md"Left and right: 320, 384 or 512 pixels wide, or the whole screen. Top and bottom: as tall as the content, up to 40%, 60% or 85% of the screen, or all of it.
SheetContent: showClosebooleanDefault trueShow the close button in the top corner. Escape and a press outside close the sheet either way.
SheetContent: classNamestring–Extra classes for the panel, such as a width of your own (max-w-2xl).
SheetHeader, SheetFooterComponentProps<"div">–Layout for the title block and for the actions. The footer sits at the bottom edge and stacks its buttons on a phone.
SheetTitleheading props–The sheet's name, announced when it opens. Every sheet needs one.
SheetDescriptionparagraph props–The explanation under the title, read after the name.
SheetClosebutton props–A button that closes the sheet. Its own onClick runs first.

Motion and sound

Motion

  • The sheet slides in from its edge over 200 ms while the veil fades in.
  • Closing plays the same change backwards. Closing during the opening reverses it from where it is.
  • Reduced motion: the sheet and the veil appear and leave at once.

Sound

  • A soft rising tone when the sheet 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.
  • 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.
  • Focus moves into the sheet when it opens and goes back to the trigger when it closes. A press on the veil closes it.
  • Long content scrolls inside the sheet. The close button stays in its corner while the content scrolls; it is 28 pixels square and named Close.
  • On a phone a left or right sheet leaves a 40 pixel strip of the page, so there is always somewhere to press to close it.
  • Only the corners away from the screen edge are round, and they follow the theme's radius. The full size has square corners.
  • Under a glass material the sheet is translucent. Its tint keeps the text at 4.5 to 1 over any page.
KeysAction
Enter / SpaceOn the trigger: open the sheet. Focus moves to the first control inside it.
Tab / Shift TabMove through the controls inside the sheet. Focus cannot leave it.
EscClose the sheet. Focus returns to the trigger.

Source

components/ui/sheet.tsx
"use client";

import type { ComponentProps } from "react";
import { Dialog as SheetPrimitive } from "@base-ui/react/dialog";

import { cn } from "@/lib/utils";
import { play } from "@/lib/thrum-sound";
import { XIcon } from "@/components/icons/x";

export type SheetSide = "top" | "right" | "bottom" | "left";
export type SheetSize = "sm" | "md" | "lg" | "full";

export type SheetProps = SheetPrimitive.Root.Props & {
  /** Play a soft sound when the sheet opens and when it closes, if the visitor has sound on. */
  sound?: boolean;
};

/**
 * A panel that slides in from an edge of the screen and holds the focus until it is closed: filters, a record's
 * details, a phone's navigation. `Sheet` holds the state, `SheetTrigger` opens it, `SheetContent` is the panel.
 */
export function Sheet({ sound = true, onOpenChange, ...props }: SheetProps) {
  return (
    <SheetPrimitive.Root
      onOpenChange={(open, details) => {
        if (sound) play(open ? "open" : "close");
        onOpenChange?.(open, details);
      }}
      {...props}
    />
  );
}

/** The button that opens the sheet. Style it with `buttonClass()` or pass a `Button` through `render`. */
export function SheetTrigger(props: SheetPrimitive.Trigger.Props) {
  return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />;
}

/** A button that closes the sheet. */
export function SheetClose(props: SheetPrimitive.Close.Props) {
  return <SheetPrimitive.Close data-slot="sheet-close" {...props} />;
}

// Where the sheet sits, which corners are round (only the ones away from its edge), and where it slides from.
const SIDE: Record<SheetSide, string> = {
  right: "inset-y-0 right-0 rounded-l-xl border-l data-ending-style:translate-x-full data-starting-style:translate-x-full",
  left: "inset-y-0 left-0 rounded-r-xl border-r data-ending-style:-translate-x-full data-starting-style:-translate-x-full",
  top: "inset-x-0 top-0 rounded-b-xl border-b data-ending-style:-translate-y-full data-starting-style:-translate-y-full",
  bottom: "inset-x-0 bottom-0 rounded-t-xl border-t data-ending-style:translate-y-full data-starting-style:translate-y-full",
};
// Left and right: a width, with a 40 pixel strip of the page left to press on a phone.
const WIDTH: Record<SheetSize, string> = {
  sm: "w-[calc(100%-2.5rem)] max-w-xs",
  md: "w-[calc(100%-2.5rem)] max-w-sm",
  lg: "w-[calc(100%-2.5rem)] max-w-lg",
  full: "w-full rounded-none border-0",
};
// Top and bottom: as tall as the content, up to a share of the screen.
const HEIGHT: Record<SheetSize, string> = {
  sm: "max-h-[40dvh]",
  md: "max-h-[60dvh]",
  lg: "max-h-[85dvh]",
  full: "h-dvh rounded-none border-0",
};

export type SheetContentProps = SheetPrimitive.Popup.Props & {
  /** The edge of the screen the sheet is attached to and slides in from. */
  side?: SheetSide;
  /** Left and right: 320, 384 or 512 pixels wide, or the whole screen. Top and bottom: at most 40%, 60% or 85% of the screen's height, or all of it. */
  size?: SheetSize;
  /** Show the close button in the top corner. Escape and a press outside close the sheet either way. */
  showClose?: boolean;
};

/**
 * The panel itself, with the veil behind it. Its content scrolls inside it when it is longer than the panel.
 * It is a floating surface, so it turns to glass when the page's material asks for it.
 */
export function SheetContent({ side = "right", size = "md", showClose = true, className, children, ...props }: SheetContentProps) {
  return (
    <SheetPrimitive.Portal>
      <SheetPrimitive.Backdrop
        data-slot="sheet-backdrop"
        className="fixed inset-0 z-50 bg-background/70 transition-opacity duration-200 ease-out data-ending-style:opacity-0 data-starting-style:opacity-0 motion-reduce:transition-none"
      />
      <SheetPrimitive.Popup
        data-slot="sheet"
        data-surface="floating"
        data-side={side}
        className={cn(
          "fixed z-50 flex flex-col overflow-hidden bg-popover text-popover-foreground shadow-lg outline-none",
          "transition-[translate] duration-200 ease-out motion-reduce:transition-none",
          SIDE[side],
          side === "left" || side === "right" ? WIDTH[size] : HEIGHT[size],
          className,
        )}
        {...props}
      >
        <div data-slot="sheet-body" className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto overscroll-contain p-5">
          {children}
        </div>
        {showClose && (
          <SheetPrimitive.Close
            aria-label="Close"
            className="absolute end-3 top-3 grid size-7 cursor-pointer place-items-center rounded-md text-muted-foreground transition-colors duration-150 ease-out hover:bg-accent hover:text-accent-foreground focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring motion-reduce:transition-none"
          >
            <XIcon size={16} />
          </SheetPrimitive.Close>
        )}
      </SheetPrimitive.Popup>
    </SheetPrimitive.Portal>
  );
}

/** Title and description, kept clear of the close button. */
export function SheetHeader({ className, ...props }: ComponentProps<"div">) {
  return <div data-slot="sheet-header" className={cn("grid gap-1.5 pe-8", className)} {...props} />;
}

/** The sheet's name: every sheet needs one. Screen readers announce it when the sheet opens. */
export function SheetTitle({ className, ...props }: SheetPrimitive.Title.Props) {
  return <SheetPrimitive.Title data-slot="sheet-title" className={cn("text-base leading-5 font-semibold", className)} {...props} />;
}

export function SheetDescription({ className, ...props }: SheetPrimitive.Description.Props) {
  return <SheetPrimitive.Description data-slot="sheet-description" className={cn("text-sm text-muted-foreground", className)} {...props} />;
}

/** The actions. It sits at the bottom of the sheet when the content is short, and after the content when it scrolls. */
export function SheetFooter({ className, ...props }: ComponentProps<"div">) {
  return <div data-slot="sheet-footer" className={cn("mt-auto flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className)} {...props} />;
}

Files and dependencies

Adds
components/ui/sheet.tsx
Packages
@base-ui/react@1.9.0
Brings along
Sound engine
Icons
x

Changelog

  1. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor