---
title: "Sheet"
description: "A modal panel that opens from any edge of the window."
---

# Sheet

A modal panel that opens from any edge of the window.

## Installation

Install the shared package once in your Exact app. This version is a beta.

```sh
bun add --exact @rightui/ui@0.4.0-beta.4
```

Or choose another package manager:

```sh
npm install --save-exact @rightui/ui@0.4.0-beta.4
pnpm add --save-exact @rightui/ui@0.4.0-beta.4
yarn add --exact @rightui/ui@0.4.0-beta.4
```

Exact compilation uses Bun 1.4.2. Register Geist and Newsreader, declare the font marker and add the root provider using [Installation](/docs/installation).

### Manual source setup

Install an editable copy of the complete package:

```sh
mkdir -p vendor/rightui vendor/rightui-ui
npm pack @rightui/ui@0.4.0-beta.4 --pack-destination vendor/rightui
tar -xzf ./vendor/rightui/rightui-ui-0.4.0-beta.4.tgz -C vendor/rightui-ui --strip-components=1
bun add file:./vendor/rightui-ui
```

Keep package.json, the Contract files, ui.tamber, assets and licenses together.

### Import

```contract
use SheetContent, SheetBody, SheetFooter from "@rightui/ui/sheet"
```

## Usage

Import SheetContent, SheetBody and SheetFooter from @rightui/ui/sheet. Control open with local state, pass the ordered focusIds and restore focus in dismiss. For web, load assets/sheet.css from the package and declare rightui-sheet in app.json data. Keep form values in the parent state.

## Example

```contract
use FontWeights from "@rightui/ui"
use uiFontFamily, Button, Input from "@rightui/ui"
use SheetContent, SheetBody, SheetFooter from "@rightui/ui/sheet"

component Demo
  props
    width: number
    reduced: bool
  inject
    uiWeights: FontWeights
    uiFont: string
  state name = "Pedro Duarte"
  state username = "@peduarte"
  state side = "right"
  state profileOpen = false
  state activeSide = ""
  state profileTrigger = "sheet-open"
  state closeButton = true
  action openProfile
    side = "right"
    closeButton = true
    profileTrigger = "sheet-open"
    profileOpen = true
  action openSide(value: string)
    activeSide = value
  action openWithoutClose
    side = "right"
    closeButton = false
    profileTrigger = "sheet-open-no-close"
    profileOpen = true
  action dismiss
    profileOpen = false
    focus(profileTrigger)
  action dismissSide(value: string)
    activeSide = ""
    focus("sheet-open-" + value)
  action editName(value: string)
    name = value
  action editUsername(value: string)
    username = value
  view
    column gap="ui.space-24" min-width=0 max-width="100%"
      row justify-content="center"
        Button(id="sheet-open", label="Open", variant="outline", disabled=false, press=openProfile)
      SheetContent(id="sheet-profile", open=profileOpen, focusIds=["sheet-name", "sheet-username", "sheet-save", "sheet-dismiss"], dismiss=dismiss, title="Edit profile", description="Make changes to your profile here. Click save when you're done.", side=side, reduced=reduced, showCloseButton=closeButton)
        SheetBody()
          Input(id="sheet-name", label="Name", value=name, placeholder="Name", error="", disabled=false, edit=editName)
          Input(id="sheet-username", label="Username", value=username, placeholder="Username", error="", disabled=false, edit=editUsername)
        SheetFooter()
          Button(id="sheet-save", label="Save changes", variant="primary", disabled=false, press=dismiss)
          Button(id="sheet-dismiss", label="Close", variant="outline", disabled=false, press=dismiss)
      text "Side" role="heading" aria-level=3 font-size="ui.text-sm" font-weight=uiWeights.medium font-family=uiFontFamily(uiFont) data-rightui-font="body"
      row gap="ui.space-8" flex-wrap="wrap"
        for edge in ["top", "right", "bottom", "left"] key=edge
          Button(id="sheet-open-" + edge, label=edge, variant="outline", disabled=false, press=openSide(edge))
          SheetContent(id="sheet-" + edge, open=activeSide == edge, focusIds=["sheet-" + edge + "-save", "sheet-" + edge + "-cancel"], dismiss=dismissSide(edge), title="Edit profile", description="Make changes to your profile here. Click save when you're done.", side=edge, reduced=reduced, showCloseButton=true)
            SheetBody()
              for paragraph in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] key=paragraph
                text "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." font-size="ui.text-sm" line-height="ui.leading-relaxed" font-family=uiFontFamily(uiFont) data-rightui-font="body"
            SheetFooter()
              Button(id="sheet-" + edge + "-save", label="Save changes", variant="primary", disabled=false, press=dismissSide(edge))
              Button(id="sheet-" + edge + "-cancel", label="Cancel", variant="outline", disabled=false, press=dismissSide(edge))
      text "No Close Button" role="heading" aria-level=3 font-size="ui.text-sm" font-weight=uiWeights.medium font-family=uiFontFamily(uiFont) data-rightui-font="body"
      row
        Button(id="sheet-open-no-close", label="Open Sheet", variant="outline", disabled=false, press=openWithoutClose)

```

## Keyboard

Tab and Shift+Tab stay inside the modal. Escape, the close button and the backdrop dismiss it. Focus returns to the opening control.

## API Reference

| Property | Type |
| --- | --- |
| SheetContent.id | string |
| SheetContent.open | bool |
| SheetContent.focusIds | string[] |
| SheetContent.dismiss | action |
| SheetContent.title | string |
| SheetContent.description | string |
| SheetContent.side | string |
| SheetContent.reduced | bool |
| SheetContent.showCloseButton | bool |

## Web overlay setup

Load the packaged assets/sheet.css in the web head for viewport positioning and modal scroll locking. Native hosts use the same RightUI surfaces directly. Keep open state in the parent and restore focus in dismiss; list interactive children in focusIds.

```json
{
  "data": ["rightui-font", "rightui-sheet"],
  "host": {
    "web": {
      "head": [{ "link": { "rel": "stylesheet", "href": "/assets/sheet.css" } }]
    }
  }
}
```

## Source

File: packages/ui/sheet.contract

```contract
use FontWeights from "./typography-context.contract"
use uiFontFamily from "./typography-context.contract"
use Control from "./styles.contract"
use OverlayLayer from "./overlay-layer.contract"

// The parent controls visibility; OverlayLayer transports this authored surface to the window.
component SheetContent
  props
    id: string
    open: bool
    focusIds: string[]
    dismiss: action
    title: string
    description: string
    side: string
    reduced: bool
    showCloseButton: bool
  inject
    uiWeights: FontWeights
    uiFont: string
  slot
  derive horizontal = side == "left" or side == "right"
  derive outside = side == "left" ? "-100% 0px" : side == "right" ? "100% 0px" : side == "top" ? "0px -100%" : "0px 100%"
  derive shown = open and retained
  state focused = ""
  state retained = false
  state closing = false
  action reveal(width: number, height: number)
    if open
      retained = true
  // Keep the transported layer mounted until all three transitions reach their closed state.
  action motion(width: number, height: number)
    if not open
      if height <= 0.01
        retained = false
        closing = false
      else
        closing = true
    else if closing
      closing = false
      focus(id + "-panel")
  action rememberFocus(e: FocusEvent)
    focused = e.target
  action keys(k: string, e: KeyboardEvent)
    if not e.isComposing
      if k == "Escape"
        preventDefault()
        stopPropagation()
        dismiss()
      else if k == "Tab"
        preventDefault()
        stopPropagation()
        let targets = showCloseButton ? focusIds.concat([id + "-close"]) : focusIds
        let index = targets.indexOf(focused)
        let next = index < 0 ? (e.shiftKey ? targets.length - 1 : 0) : (index + (e.shiftKey ? targets.length - 1 : 1)) % max(1, targets.length)
        match targets.at(next)
          case some(target)
            focus(target)
          case none
            focus(id + "-panel")
  action blockScroll(e: WheelEvent)
    if not e.ctrlKey
      preventDefault()
  view
    if open or retained
      OverlayLayer(id=id, modal=true, initialFocus=id + "-panel", reduced=reduced)
        view position="absolute" width="1px" height="1px" opacity=0 pointer-events="none" aria-hidden=true resize=reveal
        view position="absolute" width="1px" height=(shown ? "100px" : "0px") min-height="0px" padding="0px" border="none" opacity=0 pointer-events="none" aria-hidden=true resize=motion
          transition=(reduced ? "none" : "height ui.duration-slow ui.easing")
        column id=id testId=id role="dialog" aria-modal=true aria-labelledby=(id + "-title") aria-describedby=(id + "-description") keycapture=keys focusin=rememberFocus data-rightui-sheet=(reduced ? "reduced" : side) position="absolute"
          inset="0px" margin="0px" padding="0px" width="100%" max-width="100%" height="100%" max-height="100%" border="none" background-color="transparent" overflow="clip" box-sizing="border-box"
          view id=(id + "-backdrop") testId=(id + "-backdrop") position="absolute" inset="0px" background-color="ui.overlay" aria-hidden=true tabindex=-1 pointer-events="auto" press=dismiss wheel=blockScroll touch-action="none"
            opacity=(shown ? 1 : 0) transition=(reduced ? "none" : "opacity ui.duration-slow ui.easing")
          column id=(id + "-panel") testId=(id + "-panel") tabindex=-1 autofocus=true outline="none" pointer-events="auto" position="absolute" top=(side == "bottom" ? "auto" : "0px") bottom=(side == "top" ? "auto" : "0px") left=(side == "right" ? "auto" : "0px") right=(side == "left" ? "auto" : "0px")
            inert=(not open) aria-hidden=(not open)
            width=(horizontal ? "75%" : "100%") max-width=(horizontal ? "24rem" : "100%") height=(horizontal ? "100%" : "auto") max-height=(horizontal ? "100%" : "50%") min-height="0px" box-sizing="border-box" overflow="auto" overscroll-behavior="contain"
            gap="ui.space-16" background-color="ui.surface" color="ui.foreground" box-shadow="ui.shadow-panel" border-color="ui.border" border-style="solid" border-width="0px"
            border-left-width=(side == "right" ? "ui.border-width" : "0px") border-right-width=(side == "left" ? "ui.border-width" : "0px") border-top-width=(side == "bottom" ? "ui.border-width" : "0px") border-bottom-width=(side == "top" ? "ui.border-width" : "0px")
            translate=(shown ? "0px 0px" : outside) transition=(reduced ? "none" : "translate ui.duration-slow ui.easing")
            column gap="ui.space-4" padding="ui.space-16" padding-top=(side == "bottom" ? "ui.space-16" : "calc(ui.space-16 + env(safe-area-inset-top))") padding-left="max(ui.space-16, env(safe-area-inset-left))" padding-right="calc(ui.space-48 + env(safe-area-inset-right))" flex-shrink=0
              text title id=(id + "-title") role="heading" aria-level=2 font-size="ui.text-base" font-weight=uiWeights.medium font-family=uiFontFamily(uiFont) color="ui.foreground" data-rightui-font="body"
              text description id=(id + "-description") font-size="ui.text-sm" line-height="ui.leading-normal" font-family=uiFontFamily(uiFont) color="ui.muted-foreground" data-rightui-font="body"
            children
            if showCloseButton
              button id=(id + "-close") testId=(id + "-close") class=Control font-weight=uiWeights.medium press=dismiss aria-label="Close" position="absolute" top=(side == "bottom" ? "ui.space-12" : "calc(ui.space-12 + env(safe-area-inset-top))") right="calc(ui.space-12 + env(safe-area-inset-right))" width="ui.space-32" height="ui.space-32" min-height="ui.space-32" padding="ui.space-8" border="none" background-color="transparent" color="ui.foreground"
                :hover
                  background-color="ui.muted"
                svg width="ui.space-16" height="ui.space-16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="ui.stroke-standard" aria-hidden=true
                  path d="m6 6 12 12M6 18 18 6"

component SheetBody
  slot
  view
    scroll flex="1 1 auto" min-height="0px" overscroll-behavior="contain" padding="0px ui.space-16" padding-left="max(ui.space-16, env(safe-area-inset-left))" padding-right="max(ui.space-16, env(safe-area-inset-right))"
      column gap="ui.space-24" min-width="0px"
        children

component SheetFooter
  slot
  view
    column gap="ui.space-8" padding="ui.space-16" padding-bottom="calc(ui.space-16 + env(safe-area-inset-bottom))" padding-left="max(ui.space-16, env(safe-area-inset-left))" padding-right="max(ui.space-16, env(safe-area-inset-right))" margin-top="auto" flex-shrink=0
      children

```
