Skip to main content

Sheet

Present a focused drawer from a viewport edge.

Props
Slots

Anatomy#

Sheet [component; no DOM]
├── Sheet.Trigger [part; slot=trigger]
├── Sheet.Close [part]
└── overlay [slot]
    └── Sheet.Content [part; slot=content]
        ├── Sheet.Header [part; slot=header]
        │   ├── Sheet.Title [part; slot=title]
        │   └── Sheet.Description [part; slot=description]
        ├── contentClose [slot]
        ├── Sheet.Body [part; slot=body]
        └── Sheet.Footer [part; slot=footer]

Content is portaled and renders inside the overlay element. With overlay={false}, that element is an unstyled wrapper without the overlay slot.

Usage#

Use Sheet for a focused drawer from a viewport edge, such as mobile navigation or an inspector. Sheet shares modal dismissal and focus behavior with Dialog.

  • Use Drawer when the surface needs swipe-to-dismiss gestures or snap points.
  • Use Dialog for a centered labeled task, or BaseDialog to compose backdrop and content yourself.
  • Use Popover for anchored content that should not take over the page, or DropdownMenu for a compact action list.
import { Button, Sheet } from 'moraine'

export function Example() {
  return (
    <Sheet>
      <Sheet.Trigger as={Button}>Open</Sheet.Trigger>
      <Sheet.Content title="Details">
        <Sheet.Body>Sheet content</Sheet.Body>
        <Sheet.Footer>
          <Sheet.Close as={Button}>Done</Sheet.Close>
        </Sheet.Footer>
      </Sheet.Content>
    </Sheet>
  )
}

Content composition#

Use Content title and description for simple cases:

<Sheet>
  <Sheet.Content title="Settings" description="Update your account.">
    <Sheet.Body>...</Sheet.Body>
    <Sheet.Footer>...</Sheet.Footer>
  </Sheet.Content>
</Sheet>

For a custom header layout, compose the anatomy parts:

<Sheet.Content>
  <Sheet.Header>
    <Sheet.Title>Settings</Sheet.Title>
    <Sheet.Description>Update your account.</Sheet.Description>
  </Sheet.Header>
  <Sheet.Body>...</Sheet.Body>
  <Sheet.Footer>...</Sheet.Footer>
</Sheet.Content>

An explicit Sheet.Header replaces the header generated by Content’s title and description. Sheet.Title and Sheet.Description connect their IDs to the surface’s accessible name and description. Without a visible title, set aria-label or aria-labelledby on Content.

Sheet.Close is an explicit close control you can place inside the root; it is separate from Content’s automatic corner close button:

  • closable={false}: hides the automatic corner close button.
  • closeIcon: replaces the corner close button’s icon.
  • translations: overrides the close accessible label. See Localization.
  • transition={false}: turns off enter and exit animations so content and overlay unmount as soon as the sheet closes.

Focus and dismissal#

modal defaults to true: focus stays inside the surface, outside content is hidden from assistive technology, and native outside pointer actions are prevented. Closing restores focus to the trigger.

Use initialFocus to choose the element that receives focus on open (or false to skip the move) and finalFocus to choose where focus returns. Both apply only while modal is true.

Setting modal={false} allows focus to leave the surface, but does not disable Escape or outside dismissal:

  • closeOnOutsideClick and closeOnEscape: control outside and Escape close requests (both default to true).
  • preventScroll: locks body scroll and defaults to the value of modal, so a non-modal surface leaves the page scrollable unless preventScroll is set.

Styling and portal#

Apply class and object style directly to each rendered part. Root classes and styles set slot defaults for every part: trigger, overlay, content, header, title, description, contentClose, body, and footer. See Customization for precedence.

Set root mount to place Content in a chosen container. This also works for controlled surfaces without a Trigger.

Side and layout#

Choose the viewport edge with root side (top, right, bottom, or left; default right), and set inset when the sheet needs space around it. Compose body and footer regions to keep the task content separate from its actions.

<Sheet side="right">
  <Sheet.Trigger as={Button}>Open settings</Sheet.Trigger>
  <Sheet.Content title="Settings" description="Fields in the body, actions in the footer.">
    <Sheet.Body>...</Sheet.Body>
    <Sheet.Footer>
      <Sheet.Close as={Button}>Done</Sheet.Close>
    </Sheet.Footer>
  </Sheet.Content>
</Sheet>

State and dismissal#

Use controlled open state when a layout owns visibility. Disable normal dismissal only when the sheet has a clear explicit close action; onClosePrevented receives blocked outside or Escape attempts.

<Sheet open={open()} onOpenChange={setOpen}>
  <Sheet.Content title="Controlled sheet">
    <Sheet.Footer>
      <Button onClick={() => setOpen(false)}>Done</Button>
    </Sheet.Footer>
  </Sheet.Content>
</Sheet>
<Sheet closeOnOutsideClick={false} closeOnEscape={false} onClosePrevented={onBlocked}>
  <Sheet.Content title="Persistent sheet">
    <Sheet.Footer>
      <Sheet.Close as={Button}>Close</Sheet.Close>
    </Sheet.Footer>
  </Sheet.Content>
</Sheet>

Keyboard interaction#

Key Description
Esc Requests dismissal when closeOnEscape is not false.
⇥ Moves focus forward; modal sheets contain focus.
Shift + Tab Moves focus backward; modal sheets contain focus.

Examples#

Basic#

Place fields in the body and Cancel/Done in the footer. The default side is right.

import { Button, Sheet } from 'moraine'

export function SettingsUsage() {
  return (
    <Sheet>
      <Sheet.Trigger as={Button}>Open Settings</Sheet.Trigger>
      <Sheet.Content title="Settings" description="Fields in the body, actions in the footer.">
        <Sheet.Body>
          <div class="text-xs text-muted-foreground py-4">
            Place settings fields in this region and actions in the footer.
          </div>
        </Sheet.Body>
        <Sheet.Footer>
          <div class="flex gap-2 w-full justify-end">
            <Sheet.Close as={Button} variant="ghost">
              Cancel
            </Sheet.Close>
            <Sheet.Close as={Button}>Done</Sheet.Close>
          </div>
        </Sheet.Footer>
      </Sheet.Content>
    </Sheet>
  )
}

Controlled#

A page button owns open. Closing from the footer reports back through onOpenChange.

import { Button, Sheet } from 'moraine'
import { createSignal } from 'solid-js'

export function StateUsage() {
  const [open, setOpen] = createSignal(false)

  return (
    <div>
      <Button onClick={() => setOpen(true)}>Open Managed Sheet</Button>
      <Sheet open={open()} onOpenChange={setOpen}>
        <Sheet.Content
          title="Controlled Sheet"
          description="Controlled open state enables external workflow triggers."
        >
          <Sheet.Body>
            <p class="text-xs text-muted-foreground py-2">
              Reactive state is managed by parent container.
            </p>
          </Sheet.Body>
          <Sheet.Footer>
            <div class="flex w-full justify-end">
              <Button size="xs" onClick={() => setOpen(false)}>
                Done
              </Button>
            </div>
          </Sheet.Footer>
        </Sheet.Content>
      </Sheet>
    </div>
  )
}

Prevent dismissal#

closeOnOutsideClick={false} and closeOnEscape={false} block overlay click and Escape, and onClosePrevented reports each blocked attempt. The footer action is the only way to close.

import { Button, Sheet } from 'moraine'
import { createSignal } from 'solid-js'

export function DismissControl() {
  const [open, setOpen] = createSignal(false)
  const [preventedCloseCount, setPreventedCloseCount] = createSignal(0)

  return (
    <div class="flex flex-wrap gap-3 items-center">
      <Sheet
        open={open()}
        onOpenChange={setOpen}
        closeOnOutsideClick={false}
        closeOnEscape={false}
        onClosePrevented={() => setPreventedCloseCount((value) => value + 1)}
      >
        <Sheet.Trigger as={Button} variant="outline">
          Open persistent sheet
        </Sheet.Trigger>
        <Sheet.Content
          title="Persistent sheet"
          description="Outside click and Escape key dismissal are blocked."
        >
          <Sheet.Body>
            <div class="py-2 space-y-3">
              <p class="text-sm text-muted-foreground">
                This sheet cannot be dismissed by clicking the overlay or pressing Escape.
              </p>
              <p class="text-sm text-foreground">
                Prevented close attempts: <span class="font-medium">{preventedCloseCount()}</span>
              </p>
            </div>
          </Sheet.Body>
          <Sheet.Footer>
            <div class="flex w-full justify-end">
              <Button size="sm" onClick={() => setOpen(false)}>
                Close sheet
              </Button>
            </div>
          </Sheet.Footer>
        </Sheet.Content>
      </Sheet>
    </div>
  )
}

Sides#

Set side (left, right, top, or bottom) to anchor the sheet to any viewport edge.

import { Button, Sheet } from 'moraine'

export function Sides() {
  return (
    <div class="flex flex-wrap gap-3 items-center">
      <Sheet side="left">
        <Sheet.Trigger as={Button} variant="outline" size="sm" leading="i-lucide:panel-left">
          Left (Navigation)
        </Sheet.Trigger>
        <Sheet.Content title="Application Navigation" description="Jump to any workspace section.">
          <Sheet.Body>
            <div class="py-2 space-y-2">
              <Button
                variant="ghost"
                class="w-full justify-start"
                leading="i-lucide:layout-dashboard"
              >
                Dashboard
              </Button>
              <Button
                variant="ghost"
                class="w-full justify-start"
                leading="i-lucide:git-pull-request"
              >
                Pull Requests
              </Button>
              <Button variant="ghost" class="w-full justify-start" leading="i-lucide:server">
                Deployments
              </Button>
              <Button variant="ghost" class="w-full justify-start" leading="i-lucide:settings">
                Settings
              </Button>
            </div>
          </Sheet.Body>
        </Sheet.Content>
      </Sheet>

      <Sheet side="right">
        <Sheet.Trigger as={Button} variant="outline" size="sm" leading="i-lucide:shopping-cart">
          Right (Cart Drawer)
        </Sheet.Trigger>
        <Sheet.Content
          title="Shopping Cart (2 items)"
          description="Review your selected items before checkout."
        >
          <Sheet.Body>
            <div class="text-xs py-2 space-y-3">
              <div class="p-2 rounded-lg bg-muted/40 flex items-center justify-between">
                <div>
                  <p class="font-medium">Canvas backpack</p>
                  <p class="text-muted-foreground">Qty: 1</p>
                </div>
                <span class="font-mono font-semibold">$199.00</span>
              </div>
              <div class="p-2 rounded-lg bg-muted/40 flex items-center justify-between">
                <div>
                  <p class="font-medium">Travel organizer</p>
                  <p class="text-muted-foreground">Qty: 1</p>
                </div>
                <span class="font-mono font-semibold">$49.00</span>
              </div>
            </div>
          </Sheet.Body>
          <Sheet.Footer>
            <Button class="w-full">Proceed to Checkout ($248.00)</Button>
          </Sheet.Footer>
        </Sheet.Content>
      </Sheet>

      <Sheet side="bottom">
        <Sheet.Trigger as={Button} variant="outline" size="sm" leading="i-lucide:share-2">
          Bottom (Share)
        </Sheet.Trigger>
        <Sheet.Content
          title="Share Resource"
          description="Share this repository or report with teammates."
        >
          <Sheet.Body>
            <div class="py-2 flex flex-wrap gap-2">
              <Button variant="outline" size="sm" leading="i-lucide:copy">
                Copy Link
              </Button>
              <Button variant="outline" size="sm" leading="i-lucide:mail">
                Email Team
              </Button>
              <Button variant="outline" size="sm" leading="i-lucide:qr-code">
                Show QR
              </Button>
            </div>
          </Sheet.Body>
        </Sheet.Content>
      </Sheet>
    </div>
  )
}

API Reference#

Attributes#

Attributes
data-closed
Slot: sheet-triggersheet-contentsheet-overlay
Description: Present when disclosure or transition content is closed.
data-disabled
Slot: sheet-trigger
Description: Present when the component, slot, or item is disabled.
data-expanded
Slot: sheet-triggersheet-contentsheet-overlay
Description: Present when the panel, accordion, or menu is expanded.
data-overlay-scroll
Slot: sheet-overlay
Description: Present when scrolling is owned by the overlay.
data-transition
Slot: sheet-contentsheet-overlay
Description: Present while a target participates in a visibility transition.
data-header
Slot: sheet-body
Description: Present when the component renders header content.

Props#

Sheet#

Prop

Trigger#

Renders a <button> element by default.

Prop

Content#

Props for Sheet.Content. Renders a <div> element by default.

Prop

Header#

Renders a <div> element by default.

Prop

Title#

Renders a <h2> element by default.

Prop

Description#

Renders a <p> element by default.

Prop

Body#

Renders a <div> element by default.

Prop

Renders a <div> element by default.

Prop

Close#

Prop