# Sheet

A dialog that slides in from an edge of the screen and runs along it: details of a row, filters, settings, a form next to the page it changes. It shares Dialog's scrim, raised surface and close button; only the side that faces the content has a border and page corners.

**Dependencies:** npm: 3 direct, 5 total; registry: 3 direct, 4 total.

Native: iOS stable, Android stable.

## Usage

### When to use

- Work in a side panel next to the page: the details of a row, filters, a short form, a file upload.
- Navigation on a narrow screen, from the start edge, or a few choices on a phone, from the bottom.

### When not to use

- Confirming an action that destroys data. Use AlertDialog.
- A focused task that stands on its own, such as renaming a project. Use Dialog.
- A menu of actions. Use DropdownMenu.

### Native

**Sort projects**

```text
WerewolfSheet(isPresented: $open, title: "Sort projects", size: .sm) { Text("Recently edited") }
```

```text
WerewolfSheet(open = open, onOpenChange = { open = it }, title = "Sort projects", size = WerewolfSheetSize.Sm) { WerewolfText("Recently edited") }
```

**Edit details**

```text
WerewolfSheet(isPresented: $open, title: "Edit project", description: AnyView(Text("Changes are visible to everyone on your team.")), footer: AnyView(WerewolfButton(action: { open = false }) { Text("Save") })) { WerewolfInput(value: name, onValueChange: { name = $0 }) }
```

```text
WerewolfSheet(open = open, onOpenChange = { open = it }, title = "Edit project", description = { WerewolfText("Changes are visible to everyone on your team.") }, footer = { WerewolfButton(onClick = { open = false }) { WerewolfText("Save") } }) { WerewolfInput(value = name, onValueChange = { name = it }) }
```

## Variants

### side

Set on SheetContent. The edge it slides in from. right for details and forms next to a list; left for navigation; bottom for short choices on a phone; top rarely.

Values: `top`, `right`, `bottom`, `left`. Default: `right`.

### size

Set on SheetContent. Widest it gets on the left and right (sm 320px, md 448px, lg 672px), tallest on the top and bottom (a third, half, three quarters of the screen). full covers the screen along that side, with no corners.

Values: `sm`, `md`, `lg`, `full`. Default: `md`.

## Examples

### Edit details

```tsx
<Sheet>
  <SheetTrigger asChild>
    <Button variant="secondary">Edit project</Button>
  </SheetTrigger>
  <SheetContent>
    <SheetHeader>
      <SheetTitle>Edit project</SheetTitle>
      <SheetDescription>Changes are visible to everyone on your team.</SheetDescription>
    </SheetHeader>
    <Field>
      <FieldLabel>Name</FieldLabel>
      <FieldControl>
        <Input defaultValue="Werewolf" />
      </FieldControl>
    </Field>
    <SheetFooter>
      <SheetClose asChild>
        <Button variant="secondary">Cancel</Button>
      </SheetClose>
      <Button>Save</Button>
    </SheetFooter>
  </SheetContent>
</Sheet>
```

### From the bottom

Short choices on a phone, with the main action one tap away. Like the iOS system sheet it has a drag handle: swipe it down to close.

```tsx
<Sheet>
  <SheetTrigger asChild>
    <Button variant="secondary">Sort</Button>
  </SheetTrigger>
  <SheetContent side="bottom" size="sm">
    <SheetHeader>
      <SheetTitle>Sort projects</SheetTitle>
    </SheetHeader>
    <RadioGroup aria-label="Sort projects" defaultValue="recent">
      <RadioGroupItem value="recent" label="Recently edited" />
      <RadioGroupItem value="name" label="Name" />
    </RadioGroup>
  </SheetContent>
</Sheet>
```

## Do and don't

### Do

- Use it for work next to the page: the details of a row, filters, a short form.
- Give it a title, and put the main action in the footer.
- Keep it open while the user works in it; close it when the action is done.

### Don't

- Don't use it for a short confirmation; use AlertDialog or Dialog.
- Don't open a sheet from a sheet.
- Don't use it for a menu of actions; use DropdownMenu.

## Props

| Name | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
| `open` | `boolean` |  |  | Set on Sheet. Whether it is open, when you control it. Pair it with onOpenChange. Native: isPresented (SwiftUI Binding) or open (Compose). Only on web, iOS, Android. |
| `defaultOpen` | `boolean` |  | `false` | Set on Sheet. Opens it on first render, when you don't control it. Only on web, iOS, Android. |
| `onOpenChange` | `function` |  |  | Set on Sheet. Called with true or false when it opens or closes (trigger, close button, Escape, scrim). Native: called with false when the handle's accessibility action, a swipe, the scrim or the system back action closes it. Only on web, iOS, Android. |
| `title` (required) | `string` |  |  | The name of the sheet, drawn as its title and read by assistive technology (the native SheetTitle). Required: a sheet without a name does not compile. Only on iOS, Android. |
| `description` | `node` |  |  | Optional supporting text under the title. Only on iOS, Android. |
| `footer` | `node` |  |  | Actions at the end of the sheet. Only on iOS, Android. |
| `side` | `enum` | `top`, `right`, `bottom`, `left` | `right` | Set on SheetContent. The edge it slides in from. right for details and forms next to a list; left for navigation; bottom for short choices on a phone; top rarely. Deferred on iOS and Android: top, right, left. |
| `size` | `enum` | `sm`, `md`, `lg`, `full` | `md` | Set on SheetContent. Widest it gets on the left and right (sm 320px, md 448px, lg 672px), tallest on the top and bottom (a third, half, three quarters of the screen). full covers the screen along that side, with no corners. |
| `showCloseButton` | `boolean` |  | `true` | Set on SheetContent. The corner close button. Hide it only when the footer has a Cancel or Close. Only on web. Not generated for iOS and Android. |
| `swipeToDismiss` | `boolean` |  | `true` | side bottom only (ignored on other sides): drag the sheet down to close it. Start on the handle or header always, on the body only when it is scrolled to the top. Dragging up gives resistance and never grows the sheet. Release closes when the drag passes 25 percent of the sheet height or 80px, or the release speed is at least 0.5 px/ms downward; otherwise it settles back: on the web on the spring (duration-spring, ease-spring), on native with duration-medium and ease-standard. The scrim fades with the offset. Closing finishes on the web with animate-exit-spring-bottom, from where the finger left the panel, and calls onOpenChange(false) once, so focus returns to the trigger like Escape. Under reduced motion the sheet still follows the finger, but it jumps back without moving and the exit fades. Escape, the close button and the scrim keep working. Drags that start on a field, a slider or anything marked data-sheet-swipe-ignore stay with that control. On by default, like the iOS system sheet; it also shows the drag handle. |
| `handleLabel` | `string` |  | `Close` | Native only. The accessible name of the drag handle, whose accessibility action closes the sheet, because the native Sheet has no corner close button. Default EN `Close`, VI `Đóng`. A tap on the handle never closes the sheet, like the iOS grabber. The web handle is decorative, so the web SheetContent has no handleLabel: Escape, the corner close button and the scrim close it. Only on iOS, Android. |

### Slots

| Name | Required | Description |
| --- | --- | --- |
| `trigger` | no | SheetTrigger with asChild around a Button. |
| `title` | yes | SheetTitle, required for a11y. |
| `description` | no | Optional SheetDescription. |
| `content` | yes | The body: fields, details, a list. It scrolls with the panel. |
| `footer` | no | SheetFooter with the actions. |

## Anatomy

| Part | Description |
| --- | --- |
| `root` | Sheet. Holds the open state. |
| `overlay` | The scrim behind the sheet, the same as Dialog's. Behind a bottom sheet it is color-overlay-scrim-sheet, the lighter dim of the iOS system sheet (web). |
| `content` | The panel: raised fill, shadow-high, p-xl, gap-lg. It covers the full length of its side; the border and the page corners are only on the side that faces the content. |
| `header` | Top block for the title and description, gap-sm. |
| `title` | The name of the sheet: 16px medium. |
| `description` | Optional supporting text: 14px secondary. |
| `footer` | Actions at the end of the panel, however short the content is. |
| `close` | Icon button in the corner that closes the sheet, the same as Dialog's. |
| `icon` | Tabler X in the close button, 16px. |
| `hitArea` | Transparent ::before on the close button, never smaller than size-target-min. |
| `handleRow` | The row that centers the drag handle above the title, side bottom with swipeToDismiss only. A drag can always start here. |
| `handle` | The drag handle of a bottom sheet, like the grabber of the iOS system sheet: a small rounded bar that only signals the drag; a tap does not close the sheet. Its hit area is never smaller than size-target-min. Native: one accessibility element named by handleLabel whose action closes the sheet. |

## Accessibility

Role: `dialog`

| Keys | Action |
| --- | --- |
| `Escape` | Closes the sheet and returns focus to the trigger. |
| `Tab` | Cycles focus inside the sheet (focus trap). |

- A modal dialog: it traps focus, hides the rest of the page from assistive tech and closes on Escape or a scrim press.
- Always provide a SheetTitle (visible or sr-only), so the sheet has a name.
- The corner close is a button with a visually hidden Close label and a Tabler X. With showCloseButton={false}, the footer must have a Cancel or Close.
- It slides in only when the user allows motion; under prefers-reduced-motion it fades in. On close it slides back out to the same edge, faster (duration-medium, ease-exit), or fades out.
- A bottom sheet moves like the iOS system sheet: it presents, dismisses and settles back after a swipe on a critically damped spring (duration-spring, ease-spring, web only) and does not fade while it moves; its scrim is the lighter color-overlay-scrim-sheet and fades on the same spring. Under prefers-reduced-motion it fades in and out like the other sides.
- Do not open a sheet from a sheet.
- A bottom sheet stays above the on-screen keyboard on the web: it reads the visual viewport, sits on top of the keyboard, is never taller than the visible area, and scrolls a focused field into view (at once under reduced motion). Pinch zoom is not treated as a keyboard.
- Bottom sheets pad their bottom by env(safe-area-inset-bottom), which needs viewport-fit=cover in the viewport meta and falls back to 0px. Swipe to dismiss is an extra path; keyboard and screen reader users close with Escape or the close button.
- A bottom sheet follows the iOS system sheet: a drag handle at the top and a swipe down to close (swipeToDismiss, on by default). Like the iOS grabber, the handle is only a drag affordance: a tap does not close the sheet. On the web it is decorative (aria-hidden), and Escape, the corner close button and the scrim are the other ways to close. On native, where there is no corner close button, the handle is one accessibility element named by handleLabel whose action closes the sheet. With swipeToDismiss={false} there is no handle and no swipe.

## Install

```bash
npx werewolf-ui add sheet
```

Run `npx werewolf-ui init` once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See [Installation](https://www.werewolf-ui.dev/docs/installation.md) for requirements and the alternative registry setup.

```bash
npx werewolf-ui add sheet --platform ios
npx werewolf-ui add sheet --platform android
```

For iOS and Android, run `npx werewolf-ui init --platform ios` or `npx werewolf-ui init --platform android` once, then add with `--platform`. See [Installation](https://www.werewolf-ui.dev/docs/installation.md).
