Sheet

A panel that slides in from an edge of the page.

Sheets open from the right unless you set side to left, top or bottom. Drag one back toward its edge, press outside or press Escape to close it. The body scrolls when there’s more than fits.

Preview
basic.tsx
import { Button } from "~/components/ui/button"
import { Field, FieldLabel } from "~/components/ui/field"
import { Input } from "~/components/ui/input"
import {
  Sheet,
  SheetBackdrop,
  SheetBody,
  SheetClose,
  SheetContent,
  SheetDescription,
  SheetFooter,
  SheetHeader,
  SheetTitle,
  SheetTrigger,
} from "~/components/ui/sheet"
import { Stack } from "~/components/ui/stack"

export default function Example() {
  return (
    <Sheet>
      <SheetTrigger render={<Button variant="outline" />}>Agent settings</SheetTrigger>
      <SheetBackdrop />
      <SheetContent>
        <SheetHeader>
          <SheetTitle>Pagination agent</SheetTitle>
          <SheetDescription>
            Which model composes pages, and how much it may spend.
          </SheetDescription>
        </SheetHeader>
        <SheetBody>
          <Stack gap="lg">
            <Field>
              <FieldLabel>OpenRouter model</FieldLabel>
              <Input defaultValue="anthropic/claude-haiku-5.5" />
            </Field>
            <Field>
              <FieldLabel>Spending limit (USD)</FieldLabel>
              <Input defaultValue="2.00" inputMode="decimal" />
            </Field>
          </Stack>
        </SheetBody>
        <SheetFooter>
          <SheetClose render={<Button />}>Save agent settings</SheetClose>
          <SheetClose render={<Button variant="outline" />}>Cancel</SheetClose>
        </SheetFooter>
      </SheetContent>
    </Sheet>
  )
}

Dependencies

What it's built from and what's built from it in Base, read from the imports in its source.

UsesScroll AreaprimitiveTextprimitive
Used byNav SheetblockSidebar
Packages @ui-sdk/core@0.1.0-beta.20@ui-sdk/react@0.1.0-beta.20

Installation

Set the project up for Base once first, as Getting started shows. Then add it with the CLI, or by hand.

With the CLI

terminal
npx shadcn@latest add https://design.zepez.dev/r/base/sheet.json

Manually

Install its packages:

terminal
npm install @ui-sdk/core@0.1.0-beta.20 @ui-sdk/react@0.1.0-beta.20

Add the components it uses first, listed under Dependencies.

Then copy the source:

components/ui/sheet.tsx
import {
  Drawer,
  DrawerBackdrop,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerTitle,
  DrawerTrigger,
} from "@ui-sdk/react/drawer"
import type * as React from "react"

import { ScrollArea } from "~/components/ui/scroll-area"
import { textVariants } from "~/components/ui/text"
import { cn, cnState } from "~/lib/utils"

/** A panel that slides in from an edge of the page, the right one unless you set `side`. Drag it back to close. */
function Sheet({ side = "right", ...props }: React.ComponentProps<typeof Drawer>) {
  return <Drawer side={side} {...props} />
}

/** Dims the page behind the sheet. Its opacity follows the drag. */
function SheetBackdrop({ className, ...props }: React.ComponentProps<typeof DrawerBackdrop>) {
  return <DrawerBackdrop className={cnState("fixed inset-0 bg-backdrop", className)} {...props} />
}

/** The sheet itself. Give it a `SheetTitle`. */
function SheetContent({ className, ...props }: React.ComponentProps<typeof DrawerContent>) {
  return (
    <DrawerContent
      className={cnState(
        [
          textVariants({ size: "sm" }),
          "fixed m-0 flex max-h-none max-w-none flex-col gap-lg border-border bg-overlay text-overlay-foreground shadow-xl outline-none",
          "data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:left-auto data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l sm:data-[side=right]:max-w-sm",
          "data-[side=left]:inset-y-0 data-[side=left]:right-auto data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r sm:data-[side=left]:max-w-sm",
          "data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:bottom-auto data-[side=top]:h-auto data-[side=top]:w-full data-[side=top]:border-b",
          "data-[side=bottom]:inset-x-0 data-[side=bottom]:top-auto data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:w-full data-[side=bottom]:border-t",
        ].join(" "),
        className,
      )}
      {...props}
    />
  )
}

/** The title, description and anything else at the top of the sheet. */
function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="sheet-header"
      className={cn("flex flex-col gap-2xs p-lg pb-0", className)}
      {...props}
    />
  )
}

/** The sheet's body, which scrolls when there's more than fits. */
function SheetBody({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <ScrollArea className="min-h-0 flex-1">
      <div data-slot="sheet-body" className={cn("px-lg", className)} {...props} />
    </ScrollArea>
  )
}

/** Actions at the bottom of the sheet. */
function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="sheet-footer"
      className={cn("mt-auto flex flex-col gap-sm p-lg", className)}
      {...props}
    />
  )
}

/** Names the sheet. */
function SheetTitle({ className, ...props }: React.ComponentProps<typeof DrawerTitle>) {
  return (
    <DrawerTitle
      className={cnState(
        [textVariants({ size: "md", weight: "medium", family: "heading" }), "text-foreground"],
        className,
      )}
      {...props}
    />
  )
}

/** Describes the sheet. */
function SheetDescription({ className, ...props }: React.ComponentProps<typeof DrawerDescription>) {
  return (
    <DrawerDescription
      className={cnState([textVariants({ size: "sm", tone: "muted" })], className)}
      {...props}
    />
  )
}

export {
  Sheet,
  SheetBackdrop,
  SheetBody,
  DrawerClose as SheetClose,
  SheetContent,
  SheetDescription,
  SheetFooter,
  SheetHeader,
  SheetTitle,
  DrawerTrigger as SheetTrigger,
}

API reference

Generated from Base's types. Props marked ours are added here; the rest come from the ui-sdk part it wraps. Every part also accepts its element's native attributes.

Sheet

A panel that slides in from an edge of the page, the right one unless you set side. Drag it back to close.

closeOnOutsidePress

Whether pressing outside the drawer, like on its backdrop, closes it.

Type boolean · Default true, or false while the drawer isn't modal

container

Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.

Type Element | DocumentFragment | null

controller

Opens, closes and moves the drawer from anywhere, and connects triggers and outlets outside it. Create one with createDrawerController().

Type DrawerController<any, any>

debug

Logs every state change with its reason to the console, in development builds.

Type boolean

defaultOpen

Whether the dialog starts open, when uncontrolled. Focus moves into it once it's on the page.

Type boolean · Default false

defaultSnapPoint

The snap point it opens at, when uncontrolled. It opens there again each time.

Type SnapPoint · Default the first of `snapPoints`

dismissible

Whether Escape, an outside press and Android's back gesture can close the dialog. Close parts, triggers and the controller always can. Pass false while a form has unsaved changes, and ask in onDismissAttempt.

Type boolean · Default true

driver

How it moves. "pointer" follows touch, mouse and pen with a spring fitted to iOS. "scroll-snap" uses the browser's own scrolling for bottom drawers. "auto" picks scroll snap for a bottom drawer on a touch screen, unless modalAbove is set or expandOnScroll is false, and the pointer driver otherwise.

Type SheetDriverName · Default "auto"

expandOnScroll

Whether dragging toward a larger snap point on scrollable content moves the drawer first, until it's at its largest.

Type boolean · Default true

modal

true: the rest of the page is inert and doesn't scroll, focus is trapped, and an outside press only closes the drawer. "trap-focus": traps focus and leaves the page usable. false: a drawer beside the page. See modalAbove to make it modal only above a snap point.

Type boolean | "trap-focus" · Default true

modalAbove

At or below this snap point the page stays usable and undimmed, like Maps: no inert page, no scroll lock, no aria-modal, and presses beside the drawer reach the page. Above it, modal applies. Changes once the drawer comes to rest.

Type SnapPoint

onDismissAttempt

Runs when a dismissal was refused because dismissible is false, including a swipe. The drawer resists and springs back. Ask "Discard changes?" here.

Type (details: DrawerDismissAttemptDetails) => void

onOpenChange

Runs when the drawer wants to open or close. details.reason says why, "swipe" included, details.cancel() stops it, and details.returnValue carries what closed it.

Type (open: boolean, details: DialogOpenChangeDetails<DrawerOpenChangeReason>) => void

onOpenChangeComplete

Runs once the dialog has finished opening or closing, after any animation.

Type (open: boolean) => void

onPayloadChange

Runs when the payload the content shows changes: a trigger with another payload opens the drawer, or takes a non-modal drawer over while it's open, which fires no onOpenChange, and so does a controller's open({ payload }) on the open drawer. details.cancel() keeps the previous payload.

Type (payload: unknown, details: ChangeDetails<DialogPayloadChangeReason>) => void

onSnapPointChange

Runs when the drawer moves to another snap point. details.reason says why: a swipe, the handle, the keyboard, a resize or the controller.

Type (snapPoint: SnapPoint, details: ChangeDetails<DrawerSnapPointChangeReason>) => void

open

Whether the dialog is open. Pass it to control the dialog.

Type boolean

pendingAnnouncement

What screen readers hear once a Close part's action has been running for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.

Type string · Default "Loading"

persistentElements

Elements that stay usable while the dialog makes the page inert, like a chat launcher or a password manager's button. Elements, CSS selectors, or a function that returns elements, read when the dialog opens. Presses on them never close it.

Type (string | Element)[] | (() => Element[])

physics

Overrides the motion: spring, projection, rubber band and dim. Starts from sheetPhysics.ios.

Type Partial<SheetPhysics>

preventEdgeSwipe

Whether presses on the drawer near the screen's left and right edges are kept from starting iOS Safari's back and forward swipe. Taps right at those edges then don't click. Read when the content mounts.

Type boolean · Default false

side

The edge it comes from. "start" and "end" follow the writing direction.

Type Side · Default right

snapPoint

The snap point it rests on. Pass it to control it.

Type SnapPoint | null

snapPoints

Where the drawer can rest, from the edge it comes from: a fraction of the screen up to 1, pixels above 1, "…px", "…rem", "…%", or "content" for its own size. None can be larger than the drawer, which you size with CSS.

Type SnapPoint[] · Default ["content"]

themeColor

Whether <meta name="theme-color"> dims with the backdrop, so Safari's toolbars darken too. Written where motion starts and ends, never per frame.

Type boolean · Default false

SheetBackdrop

Dims the page behind the sheet. Its opacity follows the drag.

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: DrawerBackdropState) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: DrawerBackdropState) => string)

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<DrawerBackdropState>

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: DrawerBackdropState) => CSSProperties)

SheetBody

The sheet's body, which scrolls when there's more than fits.

Takes the props of a native div.

SheetContent

The sheet itself. Give it a SheetTitle.

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: DrawerContentState<unknown>) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: DrawerContentState<unknown>) => string)

container

Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.

Type Element | DocumentFragment | null

finalFocus

Where focus goes when the dialog closes while focus is inside it.

Type PopupFocusTarget · Default "trigger"

initialFocus

Where focus goes when the dialog opens. Opening with touch focuses the dialog itself, so no on-screen keyboard appears, unless this is set to something other than "auto".

Type DialogInitialFocus · Default "auto"

keepMounted

Whether the dialog stays in the page, hidden, while closed. Its content keeps its state between opens.

Type boolean · Default false

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<DrawerContentState<unknown>>

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: DrawerContentState<unknown>) => CSSProperties)

SheetDescription

Describes the sheet.

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: {}) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: {}) => string)

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<{}>

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: {}) => CSSProperties)

SheetFooter

Actions at the bottom of the sheet.

Takes the props of a native div.

SheetHeader

The title, description and anything else at the top of the sheet.

Takes the props of a native div.

SheetTitle

Names the sheet.

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: {}) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: {}) => string)

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<{}>

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: {}) => CSSProperties)

DrawerTrigger

The button that opens the drawer. A trigger outside the drawer, like one per table row, connects through controller.

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: DialogTriggerState) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: DialogTriggerState) => string)

controller

Connects a trigger outside the drawer, like one per table row, to the drawer with this controller.

Type DrawerController<any, any>

disabled

Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless focusableWhenDisabled is set.

Type boolean · Default false

focusableWhenDisabled

Keeps a disabled trigger in the tab order with aria-disabled instead of the native attribute, so it can host a tooltip that says why. Presses still do nothing.

Type boolean · Default false

payload

Data for the content to render when this trigger opens the dialog, like the row it belongs to.

Type unknown

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<DialogTriggerState>

shortcut

A keyboard shortcut that presses the trigger, like "mod+k". mod is Command on Apple platforms and Control elsewhere. Sets aria-keyshortcuts, and a Shortcut part inside shows it. A modal dialog pauses the page's shortcuts while it's open.

Type string

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: DialogTriggerState) => CSSProperties)