Searching Puzzle Pieces

Type to search Puzzle Pieces.

Bottom Sheet

A native-dialog sheet that rises from the bottom edge, dragged and flicked with a finger, optionally resting on snap points that settle on a velocity-aware spring, with a pinned footer and a scrim that tracks the dismissal rather than the drag.

This piece is a wrapper, not a port: it renders the real <dialog-panel> and <bottom-sheet> custom elements from @magic-spells/bottom-sheet and binds attributes to them. The value here is motion — the gesture policy that decides whether a finger belongs to the sheet or to the list inside it, the velocity rules that tell a dismissal from a resize — and none of that is worth forking. The design-system bridge is four CSS custom properties.

The sheet closes itself on Escape, a backdrop tap, a downward flick, or any data-action-hide-dialog button, and reports through @hide. Your job is to flip open back to false there — see Usage.

snap: 70

Filters

Those three buttons write the snap prop, and the piece calls snapTo() for you — that is the whole controlled path. They live inside the sheet because showModal() makes everything outside it inert.

Each snap is a HEIGHT in dvh percent, not a distance to push the sheet down by. That is what keeps the footer pinned to the bottom edge and the scrollable region exactly as tall as the visible area at every rung.

This one keeps the zero-config chrome: pass title and the stock header renders a heading, generates its id and wires aria-labelledby for you. The grabber pill above it comes from the component.

A slow release settles on the nearest snap; a flick steps exactly one snap in its direction, measured from wherever the sheet actually is. Drag below the shortest rung and the gesture stops being a resize and becomes the ordinary dismiss.

Filter group 1 — scroll this list, then lift your finger and start a second gesture at the top to drag the sheet itself.

Filter group 2 — scroll this list, then lift your finger and start a second gesture at the top to drag the sheet itself.

Filter group 3 — scroll this list, then lift your finger and start a second gesture at the top to drag the sheet itself.

Filter group 4 — scroll this list, then lift your finger and start a second gesture at the top to drag the sheet itself.

Filter group 5 — scroll this list, then lift your finger and start a second gesture at the top to drag the sheet itself.

Filter group 6 — scroll this list, then lift your finger and start a second gesture at the top to drag the sheet itself.

Filter group 7 — scroll this list, then lift your finger and start a second gesture at the top to drag the sheet itself.

Filter group 8 — scroll this list, then lift your finger and start a second gesture at the top to drag the sheet itself.

Installation

Copy the piece into your app — it compiles with your build and the code is yours:

puzzle add piece bottom-sheet

Like Sheet and Scroll Stack, this piece has a runtime dependency: the web component it wraps. @magic-spells/dialog-panel is a peer that npm 7+ and pnpm install for you; Yarn 1 only warns, so install it explicitly there. If you already use the Sheet piece it is the same peer, installed once.

npm install @magic-spells/bottom-sheet @magic-spells/dialog-panel
# Yarn 1 only — npm 7+ and pnpm install the peer for you
# yarn add @magic-spells/bottom-sheet @magic-spells/dialog-panel

Then merge both stylesheets into your app's style entry (app/styles/styles.css). dialog-panel owns the dialog and overlay transport; bottom-sheet.css layers the panel geometry, the grabber, the snap heights and the scrim on top of it. Without them the sheet is an unstyled full-bleed native dialog:

/* app/styles/styles.css */
@import "tailwindcss";
@import "@magic-spells/dialog-panel/css" layer(components);
@import "@magic-spells/bottom-sheet/css" layer(components);

Order matters — dialog-panel first, because bottom-sheet.css deliberately overrides several of its rules. So does layer(components): both stylesheets use plain element selectors, and an unlayered import would outrank every Tailwind utility you put on the panel.

Requires the pieces.css tokens merged into your app styles (see Introduction).

Usage

import BottomSheet from '@/components/ui/BottomSheet.pzl';
<BottomSheet open={ filtersOpen } title="Filters" @hide={ closeFilters }>
  <FilterList/>
  <Button slot="footer" @press={ apply }>Apply</Button>
</BottomSheet>

// open is EDGE-TRIGGERED: only a change to it acts. The sheet dismisses
// itself on Escape, a backdrop tap, a downward flick, or any
// [data-action-hide-dialog] descendant, then reports through @hide —
// where you flip open back to false so the next open is a fresh edge.

// parent script
events = {
  closeFilters: () => this.setData('filtersOpen', false),
};

open is edge-triggered: only a change to it acts. That is what makes a self-closing sheet safe — an unrelated re-render never re-opens a sheet the user just flicked away while your state still says it is open.

Coming from the ported piece: @close(reason) is gone. The sheet reports through @hide, whose detail carries result and triggerElement — result names the button that closed it and is null for every dismissal. dismissible has no equivalent upstream; a bottom sheet is always dismissible.

Binary sheet

Quick actions

Without snapPoints the sheet takes its content height, capped by --bs-panel-max-height (85vh), and has exactly two states: open and gone.

Drag it down more than 100px, or flick it downward faster than 0.5 px/ms, and it dismisses. A shorter drag springs back. Upward drags never dismiss — they rubber-band with resistance and return.

Every rule about snap release is inert here. There is nothing to resize to, so the whole downward drag counts as the dismissal and the scrim fades with it.

Inset, and the settle without a spring

Delivery options

inset detaches the sheet from the screen edges: all four corners take the panel radius and a gap opens on three sides. It is pure CSS — no script reads the attribute — and the off-screen position is corrected to match, so the exit still clears the gap instead of stopping short.

A detached sheet at a given snap sits slightly higher than an edge-anchored one: the snap describes the sheet, not the gap beneath it.

spring="none" opts the snap settle out of the physics and back onto a CSS curve. It changes which clock runs the settle more than how the settle reads — the default curve overshoots by about what the spring produces at its default tuning.

A footer that answers

last result: —

Delete project?

This cannot be undone.

Each button carries data-action-hide-dialog and a data-result, so @hide receives which one closed the sheet. The readout next to the trigger is that value. Escape, a backdrop tap and a flick all report null — that is how a dismissal is told apart from an answer.

Neither button has a click handler. The component closes the sheet through the panel and the page catches up in @hide, which is the one place that has to flip open back to false.

Custom header and the grabber

Summer promo

New

Filling the header slot replaces the stock title entirely, so a custom header brings its own heading and points labelledby at it. There is no is-slot-filled probe — the piece cannot render the fallback alongside your markup.

The grabber is not part of that trade. It is a pseudo-element floating inside the header's padding rather than a box in the flow, so it survives any header content; the piece pads the header's top so your markup clears it. Toggle showGrabber next to the trigger to see the pill go — the drag surfaces are unchanged either way.

The header is always a drag surface, and so is the footer. Only the content region has to decide: it hands the gesture over the moment the list runs out.

Reference

Props

openControlled, and EDGE-TRIGGERED: only a change acts. true opens, false closes. An unrelated re-render never re-opens a sheet the user already dismissed.
titleHeading text rendered by the stock header, which also generates its id and wires aria-labelledby. Ignored once the header slot is filled.
labelledbyId of the labelling heading when the header slot is filled.
snapPointsComma- or space-separated percentages of the viewport height, or an array of numbers. Each is a HEIGHT, which is what pins the footer at every rung. Sorted and deduped; anything outside 0–100 is dropped. Omit for the two-state sheet.
snapOptional-controlled resting snap in dvh percent — a VALUE, not an index. Set at mount it is also the opening rung; only a change later calls snapTo(), and a change that writes back a rung the sheet itself announced through @snapChange is absorbed — a late render can never drag the sheet back to a rung the user already left. Undeclared values are ignored, not clamped. Pair with @snapChange.
spring"attraction,friction" override for the snap settle, both dials in (0, 1); "none" settles on the CSS curve instead. Governs the SETTLE only — opening, closing and every sheet without snapPoints stay on plain transitions.
insetDetaches the sheet from all three edges and rounds every corner. CSS only; the off-screen position is corrected so the exit still clears the gap.
maxDisplayWidthLargest viewport width where the sheet may open. It also closes an open sheet when a resize crosses the limit. Above it show() returns early and no event fires.
showGrabberDefault true. false zeroes the handle pill. CSS only; the header is a drag surface either way.
classMerged onto the bottom-sheet element.
backdropClassMerged onto the dialog-backdrop element. Inert on bottom-sheet 2.0.2, which still paints the scrim on the dialog's native ::backdrop.
styleMerged onto the bottom-sheet element after the piece's own classes.

Callbacks

@hide(detail)The exit finished. detail is { result, triggerElement }: result is the data-result of the [data-action-hide-dialog] button that closed it, and null for Escape, a backdrop tap or a flick. Flip open back to false here.
@show()The entrance settled and the native dialog is in the top layer.
@snapChange(value)A release committed a different snap; the value is the new resting rung in dvh percent. Fires on commit only, never mid-drag, and never when the sheet settles back where it started.

Slots

headerFills bottom-sheet-header, replacing the title heading entirely; a filled header brings its own heading and points labelledby at it. The grabber is a pseudo-element and survives it. Always a drag surface.
footerFills bottom-sheet-footer, pinned below the content at every snap and hidden while empty. Also a drag surface. Takes one direct child, so wrap multiple buttons in a div that carries the slot attribute.
defaultUntagged children become bottom-sheet-content, the scrollable region.

CSS custom properties

Everything the ported piece exposed as tuning constants — durations, easings, the hidden-offset overshoot, the inset gaps — is a custom property on the component, tunable from your own CSS with no prop at all. The piece bridges four of them onto the design tokens (--bs-panel-background, --bs-handle-color, and the two overlay tokens) and leaves the rest at the component's defaults:

--bs-panel-max-heightCap on a sheet with no snap points (85vh). Inert once snapPoints is set — the tallest snap is the cap.
--bs-panel-border-radiusTop corner radius (25px), or all four with inset.
--bs-content-paddingHorizontal header/content inset (20px). --bs-content-padding-block adds a vertical one; --bs-footer-padding follows it, plus the safe area.
--bs-panel-hidden-offsetExtra travel past the bottom edge when hidden (20px), so the close does not read as cut short. Applied to the hidden, showing and hiding transforms alike.
--bs-transition-durationOpen, close and backdrop fade (400ms), on --bs-transition-timing. The snap settle keeps its own pair, --bs-snap-duration and --bs-snap-timing, which only reach the sheet with spring="none".
--bs-panel-inset-xSide gap in inset mode (12px); --bs-panel-inset-bottom (12px) is the gap below, added on top of the safe area.
--bs-panel-bleedOff-screen fill of panel colour below an edge-anchored sheet (60px), so an upward rubber-band drag never reveals the page beneath.
--bs-footer-backgroundFooter fill (transparent, so the panel shows through). --bs-handle-width sizes the grabber the piece already colours.

The full list lives in the component's README — these are the ones a piece consumer reaches for most.

Known gaps

Touch cannot hand a scroll to the sheet mid-gesture. The content scrolls natively, and Pointer Events do not let a gesture change owner once the browser has started panning with it, so reaching the top of a list and continuing into a drag takes two gestures: lift, then drag. A mouse or pen can reverse mid-gesture. This is the component's deliberate trade, not a piece limitation.

A keyboard activation of a data-action-hide-dialog button closes the sheet but reports result: null. A pointerless click carries coordinates of 0,0, which dialog-panel reads as a tap outside the dialog before the delegated handler runs. A mouse click reports the data-result correctly. Fix pending upstream in dialog-panel.

On the currently published pair — bottom-sheet 2.0.2 with dialog-panel 2.0.1 — two overlays paint at once, so the scrim reads darker than the 50% the piece sets: 2.0.2 still paints its scrim on the dialog's native ::backdrop and tries to hide dialog-panel's own backdrop element with a rule that loses on specificity. It is cosmetic, backdropClass has nothing visible to style until it is settled, and the component's main branch already moves the scrim onto the element.

An unfilled footer slot leaves no visible bar, but the component's :has() rule still sees the empty element and drops the dialog's own safe-area padding — so a footerless sheet loses that inset on a notched phone.

maxDisplayWidth refuses the open silently: show() returns early and no event fires, so opening above the ceiling leaves your state out of sync until you flip the flag back yourself.