Sheet
A sheet presents content from the bottom edge. The platform already does the
work: buttons open and close a native <dialog> with
invoker commands,
showModal() makes the page inert, focuses the dialog content and returns
focus on close.
<cinq-sheet> wraps the <dialog> and adds only what the platform lacks:
sheet:before-open/sheet:before-close, to cancel or defer an open or a close withwaitUntil(promise)- a drag handle: pull it down to dismiss, it snaps back otherwise
- pull up on a button that opens the sheet, to open it with a gesture
data-replaceon a button, to open the next sheet in place of the current one instead of over it- the backdrop click of
closedby="any"in Safari, which does not support it yet
Open height follows content. Position, motion and scroll lock stay in your CSS.
Install
Section titled “Install”pnpm add @agencecinq/sheetImport once:
import "@agencecinq/sheet";Then write the markup: a <dialog> inside the host, an optional drag handle,
and buttons that target the dialog id with commandfor. Without JavaScript,
the buttons still open and close the sheet: only the hooks and the gestures
are missing.
HTML is the source of truth. The component will not auto-set
role, auto-migrate attributes, or warn about missing labels. Run an a11y linter (axe, Lighthouse) to catch invalid markup.
<button type="button" commandfor="cloak-sheet" command="show-modal">Select a size</button>
<cinq-sheet> <dialog id="cloak-sheet" aria-labelledby="cloak-title" closedby="any" class="fixed inset-x-0 top-auto -bottom-4 m-0 w-auto max-w-none max-h-[calc(100dvh-4rem)] overflow-y-auto border-0 bg-white p-0 pb-4" > <div data-dom="drag-indicator" class="touch-none" aria-hidden="true"></div> <h2 id="cloak-title">Cloak of Elvenkind</h2> ... <button type="button" commandfor="cloak-sheet" command="request-close">Close</button> </dialog></cinq-sheet>closedby="any" adds backdrop press to Escape. Anchor the dialog with
top-auto to override the UA top: 0. A small overhang (-bottom-4 with
pb-4) keeps the bottom edge hidden while the panel moves. Cap the height with
max-height.
Markup
Section titled “Markup”| Element / attribute | Required | Role |
|---|---|---|
<cinq-sheet> |
Yes | Host. Wraps one <dialog>. |
<dialog id> |
Yes | The panel. Buttons target its id with commandfor. |
closedby on <dialog> |
No | Dismissal of a modal sheet. See below. |
popover on <dialog> |
No | Makes a non-modal sheet. See Non-modal sheet. |
[data-dom="drag-indicator"] |
No | Drag handle inside the dialog. |
autofocus |
No | Element focused on open. Defaults to the first focusable element. |
data-replace on a button that opens |
No | Opens the target in place of the sheet holding the button. |
Dismissal of a modal sheet is the native closedby attribute. The handle reads
it too:
closedby |
Escape | Backdrop press | Handle pull |
|---|---|---|---|
any |
Yes | Yes | Yes |
closerequest |
Yes | No | Yes |
| absent | Yes | No | Yes |
none |
No | No | No |
[data-dom="drag-indicator"] inside the dialog is the optional drag handle.
Release it past 80 px, or with a quick downward flick, to close. Otherwise the
sheet snaps back, as it does when the browser cancels the drag. A pull upward
gives a damped rubber band. The host carries [dragging] while the handle is
pulled.
Commands
Section titled “Commands”| Button | Sheet | Effect | Hook |
|---|---|---|---|
command="show-modal" |
Modal | Opens the dialog. | sheet:before-open |
command="request-close" |
Modal | Closes the dialog. The button value becomes dialog.returnValue. |
sheet:before-close |
command="close" |
Modal | Closes the dialog at once. | None |
command="toggle-popover" |
Non-modal | Opens or closes the dialog. | sheet:before-open or sheet:before-close |
command="show-popover" |
Non-modal | Opens the dialog. | sheet:before-open |
command="hide-popover" |
Non-modal | Closes the dialog. | sheet:before-close |
On a modal sheet, Escape, the backdrop press and the handle pull go through
sheet:before-close too. Direct calls skip the hooks, like on the platform:
dialog.showModal(), dialog.close(), <form method="dialog">, and Escape
when the browser forces the close.
Pull up to open
Section titled “Pull up to open”A button that opens the sheet also opens it on a pull up past 40 px, or a
quick upward flick. A tap still runs the command. A pull that falls short does
nothing. On touch screens, set touch-action: none on the button that should
take the gesture, typically a handle outside the sheet. Buttons without it keep
page scroll.
<button type="button" class="touch-none" commandfor="cloak-sheet" command="show-modal" aria-label="Show sizes"> <span class="h-0.75 w-9 rounded-full bg-[#e9e9e9]"></span></button>Methods
Section titled “Methods”| Method | Description |
|---|---|
show() |
Opens the sheet. Resolves true if this call opened it, false if already open or canceled. |
close(returnValue?) |
Closes the sheet. Resolves true if this call closed it, false if already closed or canceled. |
init() |
Binds listeners. Called on connect. |
destroy() |
Removes listeners and closes the dialog. Called on disconnect. |
Events
Section titled “Events”Prefer the constants from @agencecinq/utils (EVENTS.SHEET_*). Events are
dispatched on document.documentElement.
| Event | Cancelable | Detail payload | Description |
|---|---|---|---|
sheet:before-open |
Yes | { sheet, instance, trigger, waitUntil } |
Fired before the dialog opens. preventDefault() cancels, waitUntil(promise) defers. |
sheet:before-close |
Yes | { sheet, instance, waitUntil } |
Fired before the dialog closes. preventDefault() cancels, waitUntil(promise) defers. |
detail.sheet is the dialog id. Once the dialog opens or closes, it fires
the native toggle event (event.newState is "open" or "closed"), in both
modes.
Deferring open or close
Section titled “Deferring open or close”Call preventDefault() to cancel, or pass a promise to detail.waitUntil() to
defer until async work finishes:
import { EVENTS } from "@agencecinq/utils";
document.documentElement.addEventListener(EVENTS.SHEET_BEFORE_CLOSE, (event) => { if (event.detail.sheet !== "cloak-sheet") return;
event.detail.waitUntil(doAsyncWork());});Several listeners can defer the same action: the sheet waits for every
promise, and a rejected one cancels the action. Call waitUntil()
synchronously in the listener. A vetoed handle pull snaps back.
UX: defer open with before-open when the fetch is short (roughly under
500 ms) and the sheet would feel broken if empty. For slower loads, open
immediately and fetch on toggle. Defer close with before-close when
you need to save or run an exit animation before dismissing.
TypeScript: import BeforeOpenDetail and BeforeCloseDetail from
@agencecinq/sheet to type listeners.
Non-modal sheet
Section titled “Non-modal sheet”Add popover to the <dialog> when the page must stay usable while the sheet
is open, such as a sticky purchase bar. Buttons toggle it with
command="toggle-popover":
<button type="button" commandfor="size-sheet" command="toggle-popover">Select a size</button>
<cinq-sheet> <dialog id="size-sheet" popover aria-labelledby="size-title">...</dialog></cinq-sheet>The browser handles the rest: aria-expanded on the buttons, Escape, a press
outside the sheet, focus moved into the dialog and back to the button on close,
and one sheet open at a time. Focus is not contained.
The popover sits in the top layer: position it against the viewport.
Escape and a press outside close it without sheet:before-close: the browser
does not let a popover cancel them. Buttons, the handle and close() still go
through the hook. A <form method="dialog"> does not close a popover: close it
on submit.
With popover="manual", a press outside and Escape leave the sheet open, so the
page around it stays fully usable, like a map under a place card (see the
map example). Buttons, the handle and close() close
it. On a popover sheet, closedby only matters to the handle: closedby="none"
turns the pull off. Close requests are left to the page: open a
CloseWatcher
on toggle to close the sheet on Escape or the back gesture, as the map example
does.
Set inert on the content the sheet covers while it is open. Lift it on the
dialog beforetoggle, before the close, so focus can return to the button:
dialog.addEventListener("beforetoggle", (event) => { covered.inert = event.newState === "open";});Motion
Section titled “Motion”While the handle is pulled, the host sets --cinq-sheet-drag-offset in px. It
is negative and damped on an upward pull. Apply it, and the enter and exit
motion, in your CSS. max(-1rem, ...) caps the rubber band at the overhang so
no gap shows under the panel. Tailwind open: matches both [open] and
:popover-open.
cinq-sheet dialog { translate: 0 max(-1rem, var(--cinq-sheet-drag-offset, 0px)); transition: translate 300ms ease-out, display 300ms allow-discrete, overlay 300ms allow-discrete;}
cinq-sheet dialog:not([open], :popover-open) { translate: 0 100%;}
@starting-style { cinq-sheet dialog:is([open], :popover-open) { translate: 0 100%; }}
cinq-sheet[dragging] dialog { transition: none;}
@media (prefers-reduced-motion: reduce) { cinq-sheet dialog { transition: none; }}Style the scrim of a modal sheet with dialog::backdrop. Set
touch-action: none on the handle so touch pulls are not taken by page scroll.
Background scroll
Section titled “Background scroll”Not handled by the package. showModal() makes the page inert but does not
lock scroll:
html:has(cinq-sheet > dialog:modal) { overflow: hidden;}Accessibility
Section titled “Accessibility”Focus on open and restore on close are native <dialog> and popover
behaviors. The rest is markup:
- A visible close button. Escape is not discoverable, and the button is the
only way out with
closedby="none" autofocuson the control the user came for, such as the first size- In a non-modal sheet,
inerton the content the sheet covers, lifted onbeforetoggle
Shopify (Liquid snippet)
Section titled “Shopify (Liquid snippet)”If you are integrating in a Shopify theme, you can use the provided snippet and Vite plugin. The plugin requires Node.js 18+.
1) Copy the snippet automatically (Vite)
Section titled “1) Copy the snippet automatically (Vite)”import { defineConfig } from 'vite';import { cinqSheetPlugin } from '@agencecinq/sheet/plugin';
export default defineConfig({ plugins: [cinqSheetPlugin()],});This copies the package snippet to your theme:
snippets/cinq-sheet.html.liquid
2) Render the snippet
Section titled “2) Render the snippet”{% capture panel %} <h2 id="size-sheet-title">Cloak of Elvenkind</h2> <p>Pick a wearer size before the griffon leaves.</p>{% endcapture %}
{% render 'cinq-sheet.html', id: 'size-sheet', label: 'size-sheet-title', content: panel%}
<button type="button" commandfor="size-sheet" command="show-modal">Select a size</button>The snippet sets closedby="any" and ships the motion classes. Pass
closedby: 'none' to block every dismissal but your own close control.
Older browsers
Section titled “Older browsers”Invoker commands need Chrome 135, Firefox 144 or Safari 26.2. For older browsers, load the invokers polyfill before the component.
Migration from 2.x
Section titled “Migration from 2.x”Version 3.0 drops <cinq-sheet-button>: buttons target the dialog with
commandfor and keep the pull up to open, the id moves to the <dialog>,
data-modal="false" becomes popover, and sheet:toggle, sheet:open and
sheet:close give way to the native toggle event. Step-by-step guide in the
README.
Playground (live)
Section titled “Playground (live)”Modal, fixed to the viewport
Section titled “Modal, fixed to the viewport”The usual setup: a modal sheet fixed to the bottom of the viewport. Prepare
up to three spells. The first one gets focus on open and the page does not
move. Pull the handle down, press Escape, tap the backdrop or memorize to
close.
Spellbook
Elminster rests for the night. Prepare tomorrow's 3rd-level spells: three slots, five spells in the book.
No spells memorized yet.
Sticky add to cart
Section titled “Sticky add to cart”A product page in a phone frame, with a sticky add to cart. A purchase bar stands in for the main button whenever it is out of view. Its button, or a pull up on its handle, opens a modal sheet on the sizes. Pick a size, open the size guide (a drawer over the sheet), then pull the handle down, tap the backdrop, press Escape or add the cloak to your hoard.
Map of the Sword Coast
Section titled “Map of the Sword Coast”A non-modal sheet (popover="manual") over a map that stays usable. Tap a place
to open its card, tap another one to switch the card without closing it, and
send the party on the road with Travel here. Close with the button, a pull
on the handle or Escape, which the example brings back with CloseWatcher
(and the back gesture on Android), or a plain Escape listener where it is
missing.