Menu

Components

Sheet

A panel that slides in from the edge of the screen for a form, some details or a menu. Set isMobile for a bottom sheet made for phones.

Introduction

Sheet is a panel that slides in from the edge of the screen and holds what does not need a whole page: a profile to edit, the details of a row, a menu. By default it is a side sheet, on the right, with a header, a body, a footer and an X in the corner. Set isMobile on it and it becomes the form made for phones: a bottom sheet with a handle.

  • isMobile is a boolean. false, the default, is a side sheet. true is a bottom sheet full width on a phone, with a handle that is dragged to close it.
  • A side sheet slides in from any of the four edges, in five sizes. The X closes it, and so do Escape and a click outside.
  • A mobile sheet can have snapPoints, such as [0.4, 0.7, 1]: it rests on one of those fractions of the screen and is dragged between them, counting the speed of the drag, and dragging past the lowest closes it. The handle has keyboard support: tap it or press the arrow keys.
  • It behaves like a modal: the page behind is dimmed and cannot be used, focus stays inside, and it goes back to the button that opened it. The motion is skipped for people who prefer reduced motion.

Use the same Sheet for both: switch isMobile on when the screen is a phone's. For a window in the middle of the screen, use Modal or Dialog. For a panel with more looks (floating, sticky, nested), use Drawer.

Installation

centerUI has no CLI or registry yet: components are copied into your project. Sheet uses Button for its close buttons.

# bun
bun add react-aria-components tailwind-variants tailwind-merge clsx

# pnpm
pnpm add react-aria-components tailwind-variants tailwind-merge clsx

# npm
npm install react-aria-components tailwind-variants tailwind-merge clsx

Add Button first (see its Manual installation), then follow the steps below.

Manual installation

Copy these files into your project and keep the paths, or adjust the imports.

1. Add the styles

src/types/sheet-styles.tsShow code
import { tv } from "tailwind-variants";

// Styles for Sheet. It has two forms, chosen with `isMobile`:
// - false (the default): a panel on one side of the screen, as in shadcn/ui and
//   Intent UI. `dialog` is the panel.
// - true: a bottom sheet for phones, with a handle that is dragged. The panel is
//   a div inside the dialog (`panel`), which the component resizes and moves
//   with pointer events and a CSS transition on height.
// The backdrop fades with `dialog-overlay` and the sheet slides with
// `drawer-modal` (see globals.css, shared with Dialog and Drawer): the `modal`
// sets `--drawer-offset` to where it comes from.
export const sheetStyles = tv({
  slots: {
    overlay: "dialog-overlay fixed inset-0 z-50 flex bg-black/50",
    modal: "drawer-modal w-full",
    // `group/sheet` lets the parts below tell the two forms apart.
    dialog: "group/sheet outline-none",
    panel: [
      "group/sheet relative flex w-full flex-col overflow-hidden rounded-t-3xl border border-b-0 bg-card text-card-fg shadow-xl",
      "transition-[height,transform] duration-300 ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none",
    ],
    // The strip at the top that is grabbed to drag the sheet. It is a button
    // when the sheet has snap points, so the keyboard can use it too.
    grip: [
      "group/grip flex shrink-0 justify-center pt-3 pb-2 outline-none",
      "touch-none select-none",
      "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",
    ],
    handle:
      "h-1.5 w-10 rounded-full bg-muted-fg/30 transition-colors group-hover/grip:bg-muted-fg/50",
    header: [
      "flex flex-col gap-1.5 px-6 pt-6 pr-12 pb-4",
      // The handle sits above the header on a mobile sheet and gives it room.
      "group-data-mobile/sheet:pt-2",
    ],
    title: "m-0 text-lg leading-snug font-semibold",
    description: "m-0 text-sm text-muted-fg",
    body: "min-h-0 flex-1 overflow-y-auto px-6 py-2 text-sm",
    footer: [
      "mt-auto flex flex-col-reverse gap-2 px-6 pt-4 pb-6 sm:flex-row sm:justify-end",
      // Leave room for the home bar of a phone.
      "group-data-mobile/sheet:pb-[max(1.5rem,env(safe-area-inset-bottom))]",
    ],
    close: "absolute top-3 right-3",
  },
  variants: {
    isMobile: {
      true: {
        overlay: "items-end justify-center",
        modal: "[--drawer-offset:translateY(100%)]",
        dialog: "block w-full",
      },
      false: {
        dialog:
          "relative flex h-full max-h-[inherit] flex-col bg-card text-card-fg shadow-xl",
      },
    },
    // The edge a side sheet is on. A mobile sheet is always at the bottom.
    placement: {
      right: {},
      left: {},
      top: {},
      bottom: {},
    },
    // A side sheet: how wide it is (top and bottom: how tall it can grow). A
    // mobile sheet: the widest it gets on a large screen.
    size: {
      sm: {},
      md: {},
      lg: {},
      xl: {},
      full: {},
    },
    // A mobile sheet without a handle needs room at the top of its own.
    hasHandle: {
      true: {},
      false: { panel: "pt-4" },
    },
  },
  compoundVariants: [
    // Side sheet, by edge.
    {
      isMobile: false,
      placement: "right",
      class: {
        overlay: "justify-end",
        modal: "h-full [--drawer-offset:translateX(100%)]",
        dialog: "border-l",
      },
    },
    {
      isMobile: false,
      placement: "left",
      class: {
        overlay: "justify-start",
        modal: "h-full [--drawer-offset:translateX(-100%)]",
        dialog: "border-r",
      },
    },
    {
      isMobile: false,
      placement: "top",
      class: {
        overlay: "items-start",
        modal: "[--drawer-offset:translateY(-100%)]",
        dialog: "border-b",
      },
    },
    {
      isMobile: false,
      placement: "bottom",
      class: {
        overlay: "items-end",
        modal: "[--drawer-offset:translateY(100%)]",
        dialog: "border-t",
      },
    },
    // Side sheet, by size: the width on the left and the right.
    ...(["right", "left"] as const).flatMap((placement) => [
      {
        isMobile: false,
        placement,
        size: "sm" as const,
        class: { modal: "max-w-xs" },
      },
      {
        isMobile: false,
        placement,
        size: "md" as const,
        class: { modal: "max-w-sm" },
      },
      {
        isMobile: false,
        placement,
        size: "lg" as const,
        class: { modal: "max-w-lg" },
      },
      {
        isMobile: false,
        placement,
        size: "xl" as const,
        class: { modal: "max-w-2xl" },
      },
      {
        isMobile: false,
        placement,
        size: "full" as const,
        class: { modal: "max-w-none" },
      },
    ]),
    // ...and how tall it can grow on the top and the bottom.
    ...(["top", "bottom"] as const).flatMap((placement) => [
      {
        isMobile: false,
        placement,
        size: "sm" as const,
        class: { modal: "max-h-[35dvh]" },
      },
      {
        isMobile: false,
        placement,
        size: "md" as const,
        class: { modal: "max-h-[55dvh]" },
      },
      {
        isMobile: false,
        placement,
        size: "lg" as const,
        class: { modal: "max-h-[80dvh]" },
      },
      {
        isMobile: false,
        placement,
        size: "xl" as const,
        class: { modal: "max-h-[95dvh]" },
      },
      {
        isMobile: false,
        placement,
        size: "full" as const,
        class: { modal: "h-dvh max-h-none" },
      },
    ]),
    // Mobile sheet, by size.
    { isMobile: true, size: "sm", class: { modal: "max-w-sm" } },
    { isMobile: true, size: "md", class: { modal: "max-w-lg" } },
    { isMobile: true, size: "lg", class: { modal: "max-w-2xl" } },
    { isMobile: true, size: "xl", class: { modal: "max-w-4xl" } },
    { isMobile: true, size: "full", class: { modal: "max-w-none" } },
  ],
  defaultVariants: {
    isMobile: false,
    placement: "right",
    size: "md",
    hasHandle: true,
  },
});

2. Add the Sheet file

src/components/ui/sheet/sheet.tsxShow code
"use client";

import {
  type KeyboardEvent,
  type PointerEvent,
  type ReactNode,
  useMemo,
  useRef,
  useState,
} from "react";
import {
  Dialog as AriaDialog,
  Modal as AriaModal,
  DialogTrigger,
  type DialogTriggerProps,
  Heading,
  ModalOverlay,
} from "react-aria-components";
import { XIcon } from "@/components/icons";
import { Button, type ButtonProps } from "@/components/ui/button/button";
import { cn } from "@/lib/cn";
import { sheetStyles } from "@/types/sheet-styles";

export type SheetProps = DialogTriggerProps;

/**
 * A panel that slides in from the edge of the screen and holds a form, some
 * details or a menu, the way the Sheet of shadcn/ui and Intent UI does. It
 * behaves like a modal: the page behind is dimmed and cannot be used, focus
 * stays inside until it closes and then goes back to what opened it, and
 * Escape closes it. It is a wrapper with no look of its own: put the button
 * that opens it and a `SheetContent` inside.
 *
 * By default it is a side sheet, on the right. Set `isMobile` on
 * `SheetContent` for the form made for phones: a bottom sheet with a handle
 * that is dragged to close it, and to resize it when it has snap points.
 *
 * It is uncontrolled: it opens when the trigger is pressed. Open it from
 * elsewhere with `isOpen` and `onOpenChange`, or start open with `defaultOpen`.
 *
 * @example
 * <Sheet>
 *   <Button>Edit profile</Button>
 *   <SheetContent>
 *     <SheetHeader><SheetTitle>Edit profile</SheetTitle></SheetHeader>
 *     <SheetBody>...</SheetBody>
 *   </SheetContent>
 * </Sheet>
 */
export function Sheet(props: SheetProps) {
  return <DialogTrigger {...props} />;
}

export interface SheetContentProps {
  /**
   * The content, or a function that receives `close`, the current `snap`, and
   * `setSnap` to move the sheet to another snap point.
   */
  children: ReactNode | ((options: SheetRenderOptions) => ReactNode);
  /**
   * `false` (the default) is a side sheet: a panel on one edge, with an X in
   * the corner. `true` is the form for phones: a bottom sheet with a handle,
   * dragged to close it, and, with `snapPoints`, to resize it. The props about
   * the handle and dragging (`snapPoints`, `snap`, `defaultSnap`,
   * `onSnapChange`, `showHandle`, `isSwipeable`) only apply when it is `true`.
   */
  isMobile?: boolean;
  /** The edge a side sheet slides in from. A mobile sheet is always at the bottom. */
  placement?: "right" | "left" | "top" | "bottom";
  /**
   * Mobile only. How tall the sheet can be, as fractions of the screen height, for example
   * `[0.4, 0.75, 1]`. The sheet rests on one of them and the user drags it
   * between them, and past the lowest to close it. Without it, the sheet is as
   * tall as its content, up to 90% of the screen, and can only be dragged
   * down to close it.
   */
  snapPoints?: number[];
  /** The snap point the sheet is on, one of `snapPoints`, for a controlled sheet. */
  snap?: number;
  /** The snap point to start on, one of `snapPoints`. Defaults to the lowest. */
  defaultSnap?: number;
  /** Called when the sheet settles on another snap point. */
  onSnapChange?: (snap: number) => void;
  /** Mobile only. The bar at the top that is dragged. Defaults to `true`. */
  showHandle?: boolean;
  /** Mobile only. Let the user drag the sheet by its handle. Defaults to `true`. */
  isSwipeable?: boolean;
  /**
   * A side sheet: how wide it is (top and bottom: how tall it can grow). A
   * mobile sheet: the widest it gets on a large screen, since on a phone it is
   * always full width.
   */
  size?: "sm" | "md" | "lg" | "xl" | "full";
  /** Close when the user clicks outside. Defaults to `true`. */
  isDismissable?: boolean;
  /** Do not close on Escape. */
  isKeyboardDismissDisabled?: boolean;
  /** The X button in the corner. Defaults to `true`, and to `false` on a mobile sheet, where the handle closes it. */
  showCloseButton?: boolean;
  /** Names the sheet when it has no `SheetTitle`. */
  "aria-label"?: string;
  /** Classes for the panel. */
  className?: string;
}

export interface SheetRenderOptions {
  close: () => void;
  /** The snap point of a mobile sheet, or `undefined` without `snapPoints` or on a side sheet. */
  snap: number | undefined;
  /** Move a mobile sheet to one of its snap points. Does nothing on a side sheet. */
  setSnap: (snap: number) => void;
}

interface PanelProps extends SheetContentProps {
  close: () => void;
  isDragDisabled: boolean;
}

// How far a drag is carried on after the finger lifts, in milliseconds of the
// speed it had. A quick flick goes further than a slow drag of the same length.
const INERTIA = 120;
// Fastest a drag can end without closing the sheet by speed alone.
const FLICK_SPEED = 0.8;

function SheetPanel({
  children,
  close,
  snapPoints,
  snap,
  defaultSnap,
  onSnapChange,
  showHandle = true,
  isDragDisabled,
  size,
  showCloseButton = false,
  className,
}: PanelProps) {
  const styles = sheetStyles({ isMobile: true, size, hasHandle: showHandle });
  const points = useMemo(
    () => (snapPoints ? [...snapPoints].sort((a, b) => a - b) : null),
    [snapPoints],
  );
  const [inner, setInner] = useState(defaultSnap ?? points?.[0]);
  const current = snap ?? inner;
  // While dragging: the height in dvh (snap mode) and how far it is pulled below
  // its lowest height, in pixels. At rest both are back to null and 0.
  const [dragHeight, setDragHeight] = useState<number | null>(null);
  const [dragY, setDragY] = useState(0);
  const [isDragging, setIsDragging] = useState(false);
  // The same fact as `isDragging`, but readable by the next event before React
  // has rendered, which is what a quick tap or a flick needs.
  const dragging = useRef(false);
  const panel = useRef<HTMLDivElement>(null);
  const drag = useRef({
    startY: 0,
    startHeight: 0,
    samples: [] as { t: number; y: number }[],
    moved: 0,
    // Where the drag has taken the sheet, kept here as well as in state so the
    // end of a fast drag reads the latest, not the last render.
    height: null as number | null,
    y: 0,
  });

  const goTo = (next: number) => {
    setDragHeight(null);
    setDragY(0);
    if (snap === undefined) setInner(next);
    if (next !== current) onSnapChange?.(next);
  };

  function onPointerDown(event: PointerEvent<HTMLElement>) {
    if (
      isDragDisabled ||
      (event.pointerType === "mouse" && event.button !== 0)
    ) {
      return;
    }
    try {
      event.currentTarget.setPointerCapture(event.pointerId);
    } catch {
      // Not every pointer can be captured; the move events still arrive.
    }
    drag.current = {
      startY: event.clientY,
      startHeight: points && current !== undefined ? current * 100 : 0,
      samples: [{ t: performance.now(), y: event.clientY }],
      moved: 0,
      height: null,
      y: 0,
    };
    dragging.current = true;
    setIsDragging(true);
  }

  function onPointerMove(event: PointerEvent<HTMLElement>) {
    if (!dragging.current) return;
    const state = drag.current;
    const dy = event.clientY - state.startY;
    state.moved = Math.max(state.moved, Math.abs(dy));
    state.samples = [
      ...state.samples.slice(-4),
      { t: performance.now(), y: event.clientY },
    ];
    const unit = window.innerHeight / 100;

    if (points) {
      const min = points[0] * 100;
      const max = points[points.length - 1] * 100;
      const next = state.startHeight - dy / unit;
      if (next >= min) {
        state.height = Math.min(next, max);
        state.y = 0;
      } else {
        // Past the lowest height the sheet keeps it and slides down.
        state.height = min;
        state.y = (min - next) * unit;
      }
    } else {
      state.y = Math.max(dy, 0);
    }
    setDragHeight(state.height);
    setDragY(state.y);
  }

  function onPointerUp(event: PointerEvent<HTMLElement>) {
    if (!dragging.current) return;
    dragging.current = false;
    try {
      event.currentTarget.releasePointerCapture(event.pointerId);
    } catch {
      // Nothing was captured.
    }
    setIsDragging(false);

    const state = drag.current;
    const first = state.samples[0];
    const last = state.samples[state.samples.length - 1];
    const dt = last.t - first.t;
    // Speed in px per ms, positive downward.
    const speed = dt > 0 ? (last.y - first.y) / dt : 0;
    const carried = speed * INERTIA;
    const unit = window.innerHeight / 100;

    if (points && current !== undefined) {
      const min = points[0] * 100;
      const height = (state.height ?? current * 100) - state.y / unit;
      const projected = height - carried / unit;

      // A tap on the handle, with no drag: go to the next taller snap point.
      if (state.moved < 4) {
        const next = points.find((point) => point > current) ?? points[0];
        goTo(next);
        return;
      }
      if (projected < min * 0.8 || speed > FLICK_SPEED * 1.5) {
        close();
        return;
      }
      const nearest = points.reduce((best, point) =>
        Math.abs(point * 100 - projected) < Math.abs(best * 100 - projected)
          ? point
          : best,
      );
      goTo(nearest);
      return;
    }

    // Without snap points: down far enough, or fast enough, closes it.
    const height = panel.current?.offsetHeight ?? 0;
    if (state.y + carried > height * 0.35 || speed > FLICK_SPEED) {
      close();
      return;
    }
    setDragY(0);
  }

  function onKeyDown(event: KeyboardEvent<HTMLElement>) {
    if (!points || current === undefined) return;
    if (event.key === "ArrowUp") {
      const next = points.find((point) => point > current);
      if (next !== undefined) goTo(next);
    } else if (event.key === "ArrowDown") {
      const lower = [...points].reverse().find((point) => point < current);
      if (lower !== undefined) goTo(lower);
      else close();
    } else return;
    event.preventDefault();
  }

  const height =
    points && current !== undefined ? (dragHeight ?? current * 100) : null;
  const options: SheetRenderOptions = {
    close,
    snap: current,
    setSnap: goTo,
  };

  const gripHandlers = {
    onPointerDown,
    onPointerMove,
    onPointerUp,
    onPointerCancel: onPointerUp,
  };
  const handle = <span className={styles.handle()} />;

  return (
    <div
      ref={panel}
      data-mobile
      style={{
        height: height === null ? undefined : `${height}dvh`,
        maxHeight: height === null ? "90dvh" : undefined,
        transform: dragY > 0 ? `translateY(${dragY}px)` : undefined,
        transition: isDragging ? "none" : undefined,
      }}
      className={cn(styles.panel(), className)}
    >
      {showHandle ? (
        points ? (
          <button
            type="button"
            aria-label="Resize the sheet. The up and down arrow keys change its height."
            onKeyDown={onKeyDown}
            // Enter and Space press a button without a pointer: go to the next
            // taller snap point, as a tap does.
            onClick={(event) => {
              if (event.detail !== 0 || current === undefined) return;
              goTo(points.find((point) => point > current) ?? points[0]);
            }}
            className={styles.grip()}
            {...gripHandlers}
          >
            {handle}
          </button>
        ) : (
          <div aria-hidden="true" className={styles.grip()} {...gripHandlers}>
            {handle}
          </div>
        )
      ) : null}
      {typeof children === "function" ? children(options) : children}
      {showCloseButton ? (
        <Button
          slot="close"
          isIcon
          variant="ghost"
          size="xs"
          aria-label="Close"
          className={styles.close()}
        >
          <XIcon />
        </Button>
      ) : null}
    </div>
  );
}

/**
 * The sheet: a dimmed backdrop and a panel. By default the panel is on the
 * right edge; `placement` moves it, and `isMobile` makes it a bottom sheet
 * with a handle. It slides in and out, and not for people who prefer reduced
 * motion.
 */
export function SheetContent({
  isMobile = false,
  placement = "right",
  isDismissable = true,
  isKeyboardDismissDisabled,
  isSwipeable = true,
  size,
  showCloseButton,
  children,
  ...props
}: SheetContentProps) {
  const styles = sheetStyles({ isMobile, placement, size });

  return (
    <ModalOverlay
      isDismissable={isDismissable}
      isKeyboardDismissDisabled={isKeyboardDismissDisabled}
      className={styles.overlay()}
    >
      <AriaModal className={styles.modal()}>
        <AriaDialog
          aria-label={props["aria-label"]}
          className={cn(styles.dialog(), !isMobile && props.className)}
        >
          {({ close }) =>
            isMobile ? (
              <SheetPanel
                {...props}
                size={size}
                close={close}
                isDragDisabled={!isSwipeable}
                showCloseButton={showCloseButton}
              >
                {children}
              </SheetPanel>
            ) : (
              <>
                {typeof children === "function"
                  ? children({ close, snap: undefined, setSnap: () => {} })
                  : children}
                {(showCloseButton ?? true) ? (
                  <Button
                    slot="close"
                    isIcon
                    variant="ghost"
                    size="xs"
                    aria-label="Close"
                    className={styles.close()}
                  >
                    <XIcon />
                  </Button>
                ) : null}
              </>
            )
          }
        </AriaDialog>
      </AriaModal>
    </ModalOverlay>
  );
}

const partStyles = sheetStyles();

interface PartProps {
  children: ReactNode;
  className?: string;
}

/** The top of the sheet: the title and, under it, a line that says more. */
export function SheetHeader({ children, className }: PartProps) {
  return <div className={cn(partStyles.header(), className)}>{children}</div>;
}

/** The heading of the sheet. It also names the sheet for screen readers. */
export function SheetTitle({ children, className }: PartProps) {
  return (
    <Heading slot="title" className={cn(partStyles.title(), className)}>
      {children}
    </Heading>
  );
}

/** A line under the title that says what the sheet is for. */
export function SheetDescription({ children, className }: PartProps) {
  return <p className={cn(partStyles.description(), className)}>{children}</p>;
}

/** The middle of the sheet. It scrolls when the content is taller than the sheet. */
export function SheetBody({ children, className }: PartProps) {
  return <div className={cn(partStyles.body(), className)}>{children}</div>;
}

/** The bottom of the sheet: its buttons. It stays in view while the body scrolls. */
export function SheetFooter({ children, className }: PartProps) {
  return <div className={cn(partStyles.footer(), className)}>{children}</div>;
}

/**
 * A button that closes the sheet it is in. It is a `Button`, so it takes the
 * same variants and sizes, and `onPress` runs before the sheet closes.
 */
export function SheetClose({
  variant = "outline",
  ...props
}: Omit<ButtonProps, "slot" | "href">) {
  return <Button slot="close" variant={variant} {...props} />;
}

It imports XIcon from @/components/icons. Add the icon, or swap it for your own.

3. Add the animations

In src/app/globals.css copy the drawer-in and drawer-out keyframes, the .drawer-modal rules for [data-entering] and [data-exiting], and the reduced-motion rule that turns them off. The backdrop fades with the .dialog-overlay rules and keyframes from Dialog, so copy those too. They are shared with Drawer. Without them the sheet still works, it just appears and disappears at once.

4. Use it

import {
  Sheet,
  SheetBody,
  SheetClose,
  SheetContent,
  SheetDescription,
  SheetFooter,
  SheetHeader,
  SheetTitle,
} from "@/components/ui/sheet/sheet";

Anatomy

A trigger, and a panel with a header, a body and a footer.

<Sheet>
  <Button>Edit profile</Button>
  <SheetContent placement="right">
    <SheetHeader>
      <SheetTitle>Edit profile</SheetTitle>
      <SheetDescription>Make changes to your profile here.</SheetDescription>
    </SheetHeader>
    <SheetBody>{/* anything */}</SheetBody>
    <SheetFooter>
      <SheetClose>Cancel</SheetClose>
      <Button>Save changes</Button>
    </SheetFooter>
  </SheetContent>
</Sheet>
PartRendered asNotes
Sheetno elementHolds whether it is open. It has no look: put the button that opens it, and a SheetContent, inside.
SheetContentbackdrop and panelThe dimmed backdrop and the panel on one edge, with an X in its corner. The page behind cannot be used, and Tab stays inside. With isMobile it is a bottom sheet with a handle.
SheetHeader / SheetTitle / SheetDescriptiondiv, heading, pThe title, which also names the sheet for screen readers, and a line under it.
SheetBodydivThe middle. It scrolls when the content is taller than the sheet.
SheetFooterdivThe buttons, at the bottom. It stays in view while the body scrolls.
SheetCloseButtonA button that closes the sheet.
Handlebar at the top (isMobile)On a mobile sheet: drag it down to close the sheet, and with snap points up and down to resize it. With snap points it is a button: tap it, or use the arrow keys.

Examples

Side sheets, the default. Press a button to open one.

Usage

Placement

The edge it slides in from. Right is the default.

Sizes

On the sides, the width. On the top and the bottom, the most it grows: it is as tall as its content until then.

Scrolling

Content taller than the screen scrolls in the body, and the header and the footer stay in view.

With a form

Children can be a function that receives close. Here the form closes the sheet when it is submitted.

Nothing saved yet.

Without the X

showCloseButton hides the X in the corner. Keep a button in the footer.

Dismissing

A sheet closes on Escape and on a click outside, plus its buttons. isDismissable turns off the click outside, and isKeyboardDismissDisabled turns off Escape. Then only its buttons close it, so leave one.

Controlled

Keep whether it is open in your own state, to open it from anywhere: a menu item, a keyboard shortcut, the result of a request.

isOpen: false

Mobile

isMobile makes it a bottom sheet, the way sheets work on a phone. It has a handle that is dragged, and best tried on a phone or with the browser's device toolbar. With a mouse, drag the handle.

Bottom sheet

It rises from the bottom with rounded top corners, full width on a phone, and as tall as its content (up to 90% of the screen). Drag the handle down to close it. A flick closes it too. It has no X, because the handle does that job.

Snap points

snapPoints are fractions of the screen height. The sheet starts on the lowest one, or on defaultSnap. Drag the handle to another, tap it to go to the next taller one, or press the up and down arrow keys while it has focus. Dragging down from the lowest closes it.

Controlled snap

Keep the snap point in your own state with snap and onSnapChange, to read where the sheet rests or to move it from outside.

snap: 0.4 · isOpen: false

Render function

Children can be a function that receives close, the current snap point, and setSnap to move to another one, for a button that expands the sheet.

Not swipeable

isSwipeable={false} turns dragging off. The handle stays as a picture, and the sheet closes with its buttons, Escape or a click outside.

Without the handle

showHandle={false} leaves the handle out, and then nothing can be dragged. Add the X in the corner with showCloseButton.

Mobile sizes

On a phone a mobile sheet is as wide as the screen. On a wider screen it is centered and this wide at most.

Component API

Sheet is made of the parts below.

Sheet

PropTypeDefault
childrenReactNode- (the trigger and a SheetContent)
isOpenboolean-
defaultOpenbooleanfalse
onOpenChange(isOpen: boolean) => void-

SheetContent

PropTypeDefault
childrenReactNode | ({ close, snap, setSnap }) => ReactNode- (required)
isMobilebooleanfalse
placement"right" | "left" | "top" | "bottom""right"
size"sm" | "md" | "lg" | "xl" | "full""md"
isDismissablebooleantrue
isKeyboardDismissDisabledbooleanfalse
showCloseButtonbooleantrue (false when isMobile)
aria-labelstring- (when there is no SheetTitle)
classNamestring-

SheetContent, when isMobile

PropTypeDefault
snapPointsnumber[] (0 to 1)- (as tall as its content)
snapnumber-
defaultSnapnumberthe lowest snap point
onSnapChange(snap: number) => void-
showHandlebooleantrue
isSwipeablebooleantrue

The other parts

PartProps
SheetHeader, SheetTitle, SheetDescriptionchildren, className
SheetBody, SheetFooterchildren, className
SheetCloseany Button prop except slot and href, such as variant and onPress