drawer
onChange called 0 time(s)
Delivery day
Thursday
import { state } from '@markless/core';import { drawer, lucide } from '@markless/ui';export default function DrawerBasic() @{ let day = state('Thursday'); <drawer.root class="drawer"> <div class="card"> <p class="card-label">Delivery day</p> <p class="card-day">{day}</p> <drawer.trigger class="button open"> <lucide.truck class="icon" aria-hidden="true" /> Change day </drawer.trigger> </div> <drawer.backdrop class="backdrop"> <drawer.content class="sheet"> <drawer.title class="title">Pick a delivery day</drawer.title> <drawer.description class="description"> Drag the sheet away, press Escape, or pick a day. </drawer.description> <div class="days"> <drawer.close class="button" data-current={day === 'Wednesday'} onClick={() => { day = 'Wednesday'; }} > Wednesday </drawer.close> <drawer.close class="button" data-current={day === 'Thursday'} onClick={() => { day = 'Thursday'; }} > Thursday </drawer.close> <drawer.close class="button" data-current={day === 'Friday'} onClick={() => { day = 'Friday'; }} > Friday </drawer.close> </div> </drawer.content> </drawer.backdrop> </drawer.root>;}
.drawer { width: min(20rem, 100%); font-family: 'Shantell Sans', system-ui, sans-serif; font-size: var(--step--1); line-height: 1.5; color: var(--ink);}.card { display: grid; gap: 0.35em; justify-items: start; padding: 1em 1.1em; border: 1px solid var(--ink); border-radius: 6px;}.card-label,.card-day { margin: 0; font-family: 'Shantell Sans', system-ui, sans-serif;}.card-label { color: var(--muted-ink);}.card-day { margin-block-end: 0.5em; font-size: var(--step-0);}.button { display: inline-flex; gap: 0.5em; align-items: center; padding: 0.45em 0.9em; border: 1px solid var(--ink); border-radius: 6px; background: var(--paper); color: var(--ink); font: inherit; font-family: 'Shantell Sans', system-ui, sans-serif; cursor: pointer; transition: background 140ms ease;}.button:hover { background: color-mix(in srgb, var(--purple) 16%, var(--cream)); html.dark & { --ink: var(--on-accent); color: var(--on-accent); }}.button:active,.button[data-current],.open[ui-open] { background: color-mix(in srgb, var(--purple) 26%, var(--cream)); html.dark & { --ink: var(--on-accent); color: var(--on-accent); }}.button:focus-visible,.sheet:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px;}.sheet:focus-visible { outline-offset: -6px;}.icon { width: 1em; height: 1em; flex: none;}.backdrop { z-index: 100; background: color-mix(in oklch, var(--slab) 55%, transparent);}.backdrop[hidden] { display: none;}/* A swipe starts only on the sheet itself, so the grab bar is a pseudo-element, not a child. */.sheet { display: grid; gap: 0.75em; align-content: start; box-sizing: border-box; padding: 0.5em 1.35em 1.5em; border-block-start: 1.5px solid var(--ink); border-radius: 14px 14px 0 0; background: var(--raised); color: var(--ink); transition: translate 200ms ease; cursor: grab;}.sheet:not([ui-orientation='horizontal']) { max-inline-size: 36rem; margin-inline: auto; border-inline: 1.5px solid var(--ink);}.sheet::before { content: ''; justify-self: center; inline-size: 3em; block-size: 0.35em; margin-block: 0.4em 0.2em; border-radius: 999px; background: var(--muted-ink);}.sheet[ui-start] { padding: 1.5em 1.35em 0.5em; border-block: 0 1.5px solid var(--ink); border-radius: 0 0 14px 14px;}.sheet[ui-start]::before { order: 1;}.sheet[ui-orientation='horizontal'] { inline-size: min(20rem, 85vw); padding: 1.5em 1.35em; border-block: 0; border-inline-start: 1.5px solid var(--ink); border-radius: 14px 0 0 14px;}.sheet[ui-orientation='horizontal'][ui-start] { border-inline: 0 1.5px solid var(--ink); border-radius: 0 14px 14px 0;}.sheet[ui-orientation='horizontal']::before { display: none;}.sheet[ui-dragging] { transition: none;}.title { margin: 0; font-family: 'Joy Elia', system-ui, sans-serif; font-size: var(--step-1); font-weight: 400; line-height: 1.2; text-shadow: none;}.description { margin: 0; font-family: 'Shantell Sans', system-ui, sans-serif;}.days { display: flex; flex-wrap: wrap; gap: 0.6em;}@media (prefers-reduced-motion: reduce) { .button, .sheet { transition: none; }}
Press Change day to open the sheet. Pick a day, press Escape, or drag the sheet down. Change
orientation and start to bring it in from another edge.
A drawer is a dialog that slides in from one edge of the screen. A person can swipe it back out. Use it for a bottom sheet on a phone, or a side panel of filters or settings.
While the drawer is open, the page behind it is out of reach. A click, Tab or a screen reader
cannot get to it, and it does not scroll. Escape, a press on the backdrop, a swipe or
drawer.close puts the drawer away. Then focus goes back to the trigger.
Anatomy
A dialog that slides in from an edge and can be swiped back out.
drawer.backdrop is the layer that covers the page, and it wraps drawer.content. The content is
the sheet itself, with role="dialog". It is also the part a swipe moves. drawer.title names
the dialog, and drawer.description describes it.
The family ships a little CSS in the markless layer. It pins the backdrop over the whole screen
and pins the sheet to its edge. One plain rule of yours beats it, as Styling
explains.
A side panel
A drawer comes up from the bottom by default. Set orientation to horizontal for a side panel.
Add start to bring it from the other edge. Both follow the page's direction, so a right-to-left
page gets the mirrored side with no extra prop.
<drawer.root orientation="horizontal" start>Rest positions
snapPoints lists the places the drawer can stop. Each one is a fraction of the drawer's own size.
A number above 1 counts as pixels. A slow swipe settles on the nearest rest position. A quick flick
moves exactly one position.
<drawer.root snapPoints={[0.4, 1]} defaultSnapPoint={0.4}>Swipe past the lowest position and let go, and the drawer closes. How far past is
closeThreshold, a fraction of that lowest position. The default is 0.25.
Leave the page live
Set modal={false} and the page behind stays usable. The drawer still opens, swipes and closes.
<drawer.root modal={false}>Keyboard
Opening the drawer moves focus onto the sheet. The arrow keys work only while the sheet itself has focus. Inside your own controls, the arrow keys still belong to those controls.
| Key | What it does |
|---|---|
| Escape | Close the drawer and put focus back on the trigger. |
| Up or Down arrow | On a bottom or top sheet, move one rest position more open or more closed. |
| Left or Right arrow | The same, on a side panel. |
| Enter or Space | Press the focused trigger or close button. Both are native buttons. |
The arrows stop at the first and last rest position. With one rest position they do nothing.
API
Every prop is optional.
drawer.root
| Prop | Type | What it does |
|---|---|---|
open |
boolean |
Whether the drawer starts open. The default is false. |
modal |
boolean |
The page behind is out of reach while the drawer is open. The default is true. |
orientation |
'horizontal' | 'vertical' |
vertical is a bottom sheet and the default. horizontal is a side panel. |
start |
boolean |
Anchor the drawer at the start edge of its axis instead of the end edge. |
snapPoints |
readonly number[] |
The rest positions. The default is [1], fully open. Order does not matter. |
snapPoint |
number |
The rest position now. Passing it makes you the owner of the position. |
defaultSnapPoint |
number |
Where the drawer starts when you do not pass snapPoint. The default is the largest. |
closeThreshold |
number |
How far past the lowest rest position a swipe must go to close. The default is 0.25. |
onChange |
(open: boolean) => void |
Called with the new value when the drawer opens or closes, by any route. |
onSnapPointChange |
(snapPoint: number) => void |
Called with the rest position a swipe or a key settled on. |
When you pass snapPoint, a swipe calls onSnapPointChange. The drawer does not move until you
pass the new value back in.
| Attribute | When |
|---|---|
ui-open |
The drawer is open. |
ui-closed |
The drawer is closed. |
ui-orientation |
Always. It holds vertical or horizontal. |
ui-start |
start is set. |
ui-dragging |
A swipe is moving the sheet. Turn your transition off while it is set. |
Every other prop goes on the root <div>.
drawer.trigger
A <button> with aria-haspopup="dialog", aria-expanded and aria-controls. It writes
ui-open and ui-closed. Your own onClick runs after the drawer has opened.
drawer.backdrop
A <div> that wraps drawer.content. It gets hidden while the drawer is closed. Your own
onDismiss runs after the family has closed the drawer.
| Attribute | When |
|---|---|
ui-backdrop |
Always. Style the dimmed layer with it. |
ui-open, ui-closed |
The drawer is open or closed. |
ui-orientation, ui-start |
The same as on the root. |
| Selector | Default in the markless layer |
|---|---|
[ui-backdrop] |
position: fixed; inset: 0 |
A press on the backdrop closes the drawer only if the press also ends there. A swipe that starts on the sheet and ends on the backdrop does not close it.
drawer.content
A <div role="dialog" tabindex="-1">, so it can hold focus without being a Tab stop.
aria-modal="true" is set while modal is on. aria-labelledby points at drawer.title, and
aria-describedby at drawer.description.
Render drawer.title and it names the drawer: the content points aria-labelledby at it, with no prop. VoiceOver and NVDA both read that name, on focus and on a walk, wherever the surface sits on the page. Use aria-label on drawer.content only when there is no title. With a title rendered, aria-labelledby outranks aria-label in the accessible name, so an aria-label beside a title changes nothing.
The family owns this element's style attribute. It writes --offset there: how far the sheet is
pushed out, as a fraction of its size. Style the sheet with a class and a stylesheet, as the demo
does with sheet.
| Attribute | When |
|---|---|
ui-content |
Always. |
ui-open, ui-closed |
The drawer is open or closed. |
ui-orientation, ui-start |
The same as on the root. |
ui-dragging |
A swipe is moving the sheet. |
| Selector | Default in the markless layer |
|---|---|
[ui-content] |
position: fixed, pinned to its edge, moved by translate with --offset |
[ui-content] |
touch-action: none; overscroll-behavior: contain |
[ui-content][ui-start], [ui-content][ui-orientation=horizontal] |
The same, pinned to the other edge or side |
A press on any element inside the sheet never starts a swipe. Only a press on the sheet itself does.
drawer.title
An <h2>. Rendering it names the dialog.
drawer.description
A <p>. The dialog uses it as its description.
drawer.close
A <button>. Your own onClick runs after the drawer has closed.