Skip to main content

Drawer

Present a swipeable surface from a viewport edge with snap points.

Props
Slots

Anatomy#

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

Content is portaled. Overlay and Content are siblings by default.

Usage#

Use Drawer for a mobile-style surface the user dismisses with a swipe along its edge, optionally resting at snap points. Use Sheet for an edge panel without gestures. Use Dialog for a centered labeled task, and BaseDialog to compose backdrop and content yourself.

Drawer shares modal dismissal and focus behavior with Dialog. The default side is bottom. For a persistent panel that coexists with the page, combine modal={false} with overlay={false}, preventScroll={false}, and closeOnOverlayClick={false}. Escape and swipe dismissal still apply.

import { Button, Drawer } from 'moraine'

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

Content composition#

Use Content title and description for simple cases, or compose Drawer.Header, Drawer.Title, Drawer.Description, Drawer.Body, and Drawer.Footer for a custom layout, following the same contract as Sheet. An explicit Drawer.Header replaces the generated header. Drawer.Close is an explicit close control. Root closable (default true) adds the automatic corner close button, and closeIcon replaces its icon. The drawer message group (close) names the button, and translations overrides it per drawer. A touch swipe that starts on the button still dismisses.

Root transition={false} turns off the enter and exit animations. Content and overlay then unmount as soon as the drawer closes instead of waiting for the animation to end.

For top and bottom sides, Content renders a decorative handle grab bar along the edge facing the viewport. Set handle={false} to hide it.

Sizing and scrolling#

A top or bottom drawer sizes to its content and stops 0.5rem (or the top safe-area inset, if larger) short of the viewport height. left and right panels span w-3/4, up to sm:max-w-sm. Override either with Content class, for example class="h-[50dvh]" for a fixed height or class="w-1/2 sm:max-w-2xl" for a wider side panel. Body is the scrollable region: once Content’s height is bounded, it scrolls between the header and footer.

Swipe to dismiss#

The surface tracks a drag along its dismiss axis (down for bottom, up for top, outward for left and right) and closes once dragged past half its size or on a fast flick. A drag against the dismiss direction is damped and springs back. The data-swiping attribute on the content and overlay marks the active gesture so transitions pause.

A mouse or pen drag does not start on interactive elements (button, a, form controls, [contenteditable], [role="button"], [role="slider"]), inside Drawer.Body, which stays available for text selection, or inside a region that scrolls along the drag axis. A touch drag can start on interactive elements. Touch drags that begin inside a scrollable region defer to native scrolling until the scroller reaches its edge in the drag direction.

Mark a subtree with data-swipe-ignore to block drags that start in it. On touch, data-swipe-ignore="x" or "y" blocks only drags along that axis.

<Drawer.Body>
  <div data-swipe-ignore>Drag-free region</div>
</Drawer.Body>

Snap points#

snapPoints limits where a top or bottom drawer rests. Each entry is the visible height from the edge, in any order: numbers <= 1 are a fraction of the viewport height, larger numbers are pixels, and 'px' or 'rem' strings resolve directly. Snap points are ignored for left and right. Snap heights are clamped to the content’s rendered height and the viewport, so give Content an explicit height (for example class="h-[calc(100dvh-0.5rem)]") when using fractional or full snap points.

snapPoint, defaultSnapPoint, and onSnapPointChange control the resting point. It defaults to the first snap point, and null means fully open. Releasing a swipe settles on the closest point (projected by the swipe velocity), and dragging past the lowest point closes the drawer. With snapToSequentialPoints, a flick advances at most one point and closes only from the lowest point. After the drawer finishes closing, it returns to the default point and reports it through onSnapPointChange if the active point differed.

const [snapPoint, setSnapPoint] = createSignal<DrawerT.SnapPoint | null>('200px')

<Drawer snapPoints={['200px', 1]} snapPoint={snapPoint()} onSnapPointChange={setSnapPoint}>

CSS variables#

Content declares these variables. Override them with styles.content, or read them in your own styles.

Variable Default Description
--drawer-swipe-movement 0px Current swipe offset along the surface axis.
--drawer-snap-point-offset 0px Offset of the active snap point from fully open.
--drawer-keyboard-inset 0px Bottom inset reserved for the on-screen keyboard.
--drawer-translate per side Translate applied to the surface; derives from the swipe and snap offsets.
--drawer-max-height calc(100dvh - max(0.5rem, env(safe-area-inset-top, 0px))) Height cap for top and bottom sides.
--drawer-safe-area-bottom env(safe-area-inset-bottom, 0px) Resolved bottom safe-area inset.
--drawer-bottom-inset max of safe area and --drawer-keyboard-inset Bottom padding of a bottom drawer.
--drawer-nested-num 0 Number of open drawers nested inside this drawer.
--drawer-nested-progress 0 Swipe progress of the frontmost nested drawer in [0, 1].
--drawer-frontmost-height 0px Measured popup height of the frontmost nested drawer.
--drawer-nested-scale derived from nested count and progress (1 when none) Scale applied to recede ancestor drawers in a nested stack.
--drawer-nested-offset derived from nested count and progress (0px when none) Offset applied to push ancestor drawers upward in a nested stack.

Keyboard interaction#

Key Description
Esc Dismisses the drawer unless closeOnEscape is false.
⇥ Moves focus forward; modal drawers contain focus.
Shift + Tab Moves focus backward; modal drawers contain focus.

On Android, the system back gesture closes the drawer in browsers that support CloseWatcher. It follows closeOnEscape and reports blocked requests through onClosePrevented.

Examples#

Bottom sheet with a handle#

The default bottom side shows the grab handle and dismisses on a downward swipe.

import { Button, Drawer } from 'moraine'

export function BottomUsage() {
  return (
    <Drawer>
      <Drawer.Trigger as={Button}>Open Bottom Drawer</Drawer.Trigger>
      <Drawer.Content title="Share" description="Swipe down or pick an action to dismiss.">
        <Drawer.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>
        </Drawer.Body>
      </Drawer.Content>
    </Drawer>
  )
}

Rest at snap points#

A controlled snap point switches between a compact peek and the full-height surface.

import { Button, Drawer } from 'moraine'
import type { DrawerT } from 'moraine'
import { createSignal } from 'solid-js'

export function SnapPoints() {
  const [snapPoint, setSnapPoint] = createSignal<DrawerT.SnapPoint | null>('200px')

  return (
    <Drawer snapPoints={['200px', 1]} snapPoint={snapPoint()} onSnapPointChange={setSnapPoint}>
      <Drawer.Trigger as={Button}>Open Snap Drawer</Drawer.Trigger>
      <Drawer.Content
        class="h-[calc(100dvh-4rem)]"
        title="Snap points"
        description="Drag to rest at 200px or full height."
      >
        <Drawer.Body>
          <div class="text-xs text-muted-foreground py-4 space-y-3">
            <p>
              The drawer rests at a 200px peek or expands to the full surface. Drag the handle or
              the panel to move between them, or swipe down from the lowest point to close.
            </p>
            <div class="flex gap-2">
              <Button variant="outline" size="sm" onClick={() => setSnapPoint('200px')}>
                Peek
              </Button>
              <Button variant="outline" size="sm" onClick={() => setSnapPoint(1)}>
                Expand
              </Button>
            </div>
          </div>
        </Drawer.Body>
      </Drawer.Content>
    </Drawer>
  )
}

Nest drawers#

A child drawer opens above its parent: ancestors shrink and slide up behind it. Setting overlay={false} on the nested drawers keeps a single overlay for the whole stack. Escape, swipe, outside press, and the Android back gesture close only the topmost drawer.

import { Button, Drawer } from 'moraine'

export function Nested() {
  return (
    <Drawer>
      <Drawer.Trigger as={Button} variant="outline">
        Nested drawers
      </Drawer.Trigger>
      <Drawer.Content>
        <Drawer.Header class="text-center">
          <Drawer.Title>First step</Drawer.Title>
          <Drawer.Description>
            This is the first step. Tap the button below to continue to the next screen.
          </Drawer.Description>
        </Drawer.Header>
        <Drawer.Footer class="justify-center sm:justify-center">
          <Drawer.Close as={Button} variant="ghost">
            Cancel
          </Drawer.Close>
          <Drawer overlay={false}>
            <Drawer.Trigger as={Button} variant="outline">
              Continue
            </Drawer.Trigger>
            <Drawer.Content>
              <Drawer.Header class="text-center">
                <Drawer.Title>Second step</Drawer.Title>
                <Drawer.Description>
                  You&apos;ve reached the second step. Tap the button below to continue to the next
                  screen.
                </Drawer.Description>
              </Drawer.Header>
              <Drawer.Body>
                <div class="flex justify-center">
                  <div class="border border-border rounded-xl bg-muted shrink-0 size-48" />
                </div>
              </Drawer.Body>
              <Drawer.Footer class="justify-center sm:justify-center">
                <Drawer.Close as={Button} variant="ghost">
                  Back
                </Drawer.Close>
                <Drawer overlay={false}>
                  <Drawer.Trigger as={Button} variant="outline">
                    Continue
                  </Drawer.Trigger>
                  <Drawer.Content>
                    <Drawer.Header class="text-center">
                      <Drawer.Title>Third step</Drawer.Title>
                      <Drawer.Description>
                        You&apos;ve reached the final step. You can close this drawer or go back.
                      </Drawer.Description>
                    </Drawer.Header>
                    <Drawer.Body>
                      <div class="flex justify-center">
                        <div class="border border-border rounded-full bg-muted shrink-0 size-32" />
                      </div>
                    </Drawer.Body>
                  </Drawer.Content>
                </Drawer>
              </Drawer.Footer>
            </Drawer.Content>
          </Drawer>
        </Drawer.Footer>
      </Drawer.Content>
    </Drawer>
  )
}

Open from different edges#

Top and bottom support handles and snap points; left and right are swipe-only panels.

import { Button, Drawer } from 'moraine'

export function Sides() {
  return (
    <div class="flex flex-wrap gap-3 items-center">
      <Drawer side="bottom">
        <Drawer.Trigger as={Button} variant="outline" size="sm" leading="i-lucide:chevron-down">
          Bottom
        </Drawer.Trigger>
        <Drawer.Content title="Bottom drawer" description="Swipe down to dismiss.">
          <Drawer.Body>
            <div class="text-xs text-muted-foreground py-2">
              Bottom drawers show the handle first and follow a downward drag.
            </div>
          </Drawer.Body>
        </Drawer.Content>
      </Drawer>

      <Drawer side="top">
        <Drawer.Trigger as={Button} variant="outline" size="sm" leading="i-lucide:chevron-up">
          Top
        </Drawer.Trigger>
        <Drawer.Content title="Top drawer" description="Swipe up to dismiss.">
          <Drawer.Body>
            <div class="text-xs text-muted-foreground py-2">
              Top drawers pin to the top edge and move the handle to the end.
            </div>
          </Drawer.Body>
        </Drawer.Content>
      </Drawer>

      <Drawer side="left">
        <Drawer.Trigger as={Button} variant="outline" size="sm" leading="i-lucide:panel-left">
          Left
        </Drawer.Trigger>
        <Drawer.Content title="Left drawer" description="Swipe left to dismiss.">
          <Drawer.Body>
            <div class="text-xs text-muted-foreground py-2">
              Side drawers skip the handle and snap points.
            </div>
          </Drawer.Body>
        </Drawer.Content>
      </Drawer>

      <Drawer side="right">
        <Drawer.Trigger as={Button} variant="outline" size="sm" leading="i-lucide:panel-right">
          Right
        </Drawer.Trigger>
        <Drawer.Content title="Right drawer" description="Swipe right to dismiss.">
          <Drawer.Body>
            <div class="text-xs text-muted-foreground py-2">
              Right drawers track a horizontal drag toward the edge.
            </div>
          </Drawer.Body>
        </Drawer.Content>
      </Drawer>
    </div>
  )
}

Keep the page interactive#

modal={false}, overlay={false}, and preventScroll={false} leave the page’s pointer, focus, and scroll access intact; closeOnOverlayClick={false} keeps outside presses from dismissing the panel — both buttons update the same count.

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

export function NonModal() {
  const [count, setCount] = createSignal(0)

  return (
    <div class="max-w-sm w-full space-y-3">
      <div class="text-xs text-muted-foreground leading-relaxed">
        The panel floats without an overlay or focus trap — the page button below stays live while
        it is open. Count: {count()}
      </div>
      <div class="flex flex-wrap gap-2">
        <Button variant="outline" size="sm" onClick={() => setCount((value) => value + 1)}>
          Page action
        </Button>
        <Drawer
          modal={false}
          overlay={false}
          preventScroll={false}
          closeOnOverlayClick={false}
          closable
        >
          <Drawer.Trigger as={Button} size="sm">
            Open Panel
          </Drawer.Trigger>
          <Drawer.Content
            title="Quick actions"
            description="Escape, a downward swipe, or the close button dismisses."
          >
            <Drawer.Body>
              <div class="py-2 flex gap-2">
                <Button variant="outline" size="sm" onClick={() => setCount((value) => value + 1)}>
                  Increment
                </Button>
                <Button variant="outline" size="sm" onClick={() => setCount(0)}>
                  Reset
                </Button>
              </div>
            </Drawer.Body>
          </Drawer.Content>
        </Drawer>
      </div>
    </div>
  )
}

Swap Dialog and Drawer responsively#

createMediaQuery renders the same task in a Dialog on wide screens and a Drawer on narrow ones. Resize the window to see the trigger swap.

import { Button, Dialog, Drawer, Field, Input } from 'moraine'
import { createMediaQuery } from 'moraine/utils'
import { Show } from 'solid-js'

function ProfileFields() {
  return (
    <div class="gap-4 grid">
      <Field label="Name">
        <Input defaultValue="Sarah Connor" />
      </Field>
      <Field label="Username">
        <Input defaultValue="@sconnor" />
      </Field>
    </div>
  )
}

export function Responsive() {
  const isDesktop = createMediaQuery('(min-width: 768px)')

  return (
    <Show
      when={isDesktop()}
      fallback={
        <Drawer>
          <Drawer.Trigger as={Button} variant="outline">
            Edit Profile
          </Drawer.Trigger>
          <Drawer.Content
            title="Edit profile"
            description="Make changes to your profile here. Click save when you're done."
          >
            <Drawer.Body>
              <ProfileFields />
            </Drawer.Body>
            <Drawer.Footer>
              <Drawer.Close as={Button}>Save changes</Drawer.Close>
            </Drawer.Footer>
          </Drawer.Content>
        </Drawer>
      }
    >
      <Dialog>
        <Dialog.Trigger as={Button} variant="outline">
          Edit Profile
        </Dialog.Trigger>
        <Dialog.Content
          title="Edit profile"
          description="Make changes to your profile here. Click save when you're done."
        >
          <Dialog.Body>
            <ProfileFields />
          </Dialog.Body>
          <Dialog.Footer>
            <Dialog.Close as={Button}>Save changes</Dialog.Close>
          </Dialog.Footer>
        </Dialog.Content>
      </Dialog>
    </Show>
  )
}

API Reference#

Attributes#

Attributes
data-closed
Slot: drawer-triggerdrawer-contentdrawer-overlay
Description: Present when disclosure or transition content is closed.
data-disabled
Slot: drawer-trigger
Description: Present when the component, slot, or item is disabled.
data-expanded
Slot: drawer-triggerdrawer-contentdrawer-overlay
Description: Present when the panel, accordion, or menu is expanded.
data-swiping
Slot: drawer-contentdrawer-overlay
Description: Present while a swipe gesture is dragging the element.
data-transition
Slot: drawer-contentdrawer-overlay
Description: Present while a target participates in a visibility transition.
data-handle
Slot: drawer-content
Description: Present when the drawer grab handle is rendered.
data-nested-open
Slot: drawer-content
Description: Present on an ancestor drawer while a nested drawer is mounted.
data-nested-swiping
Slot: drawer-content
Description: Present on an ancestor drawer while a nested drawer is being dragged.
data-footer
Slot: drawer-body
Description: Present when the component renders footer content.
data-header
Slot: drawer-body
Description: Present when the component renders header content.
data-body
Slot: drawer-headerdrawer-footer
Description: Present when the component renders body content.

Props#

Drawer#

Prop

Trigger#

Renders a <button> element by default.

Prop

Content#

Props for Drawer.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#

Renders a <button> element by default.

Prop