Table of contents
ResponsiveDialog
A Dialog on a wide screen and a Drawer on a phone, from one place — the form or question that should sit in the middle of a desktop and come up from the bottom, draggable, under a thumb.
It is the two kit components, not a third implementation: below breakpoint (the viewport's width, 640px by default, Tailwind's sm) it opens as a Drawer with snapPoints; at and above it, as a Dialog. Both keep their whole contract — modal, focus moved in and trapped and given back, the page inert, body scroll locked, Escape and the backdrop close — and both take the same title, description, children and footer. Which of the two it is gets decided as it opens and holds until it has closed: rotating a phone mid-form does not tear the form down and rebuild it in the other shape. The server render has no viewport, so it draws the Dialog; a closed one renders nothing in either form, so nothing jumps.
Overlays · two-way: bind:open · keyboard contract
<script lang="ts">
import { ResponsiveDialog } from '@l4st/driftwood';
</script>
| Light | Dark |
|---|---|
![]() |
![]() |
![]() |
![]() |
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
open bind: |
boolean |
false |
Opening decides which of the two it is, for as long as it stays open. |
breakpoint |
number |
640 |
Viewport width in px below which it is a Drawer; at and above it, a Dialog. |
snapPoints |
number[] |
[0.6, 0.95] |
The Drawer's heights, as fractions of the viewport, smallest first. |
title |
string |
— | Names it for assistive tech (aria-labelledby). |
aria-label |
string |
— | Names it when there is no visible title — a dialog needs a name either way. |
description |
string |
— | One line under the title; also its aria-describedby. |
closeLabel |
string |
— | Names the close button. Left unset, each form uses its own default. |
class |
string |
— | Lands on the panel in either form. |
classes |
Classes<DialogPart | DrawerPart> |
— | Classes for the parts inside, passed to whichever form is showing: the Dialog's and the Drawer's part names (content, header, title, description, body, footer, close, closeIcon, overlay for both; positioner for the Dialog only; handle and handleBar for the Drawer only). |
children required |
Snippet |
— | The content. |
footer |
Snippet |
— | Actions. End-aligned in the Dialog; in the Drawer, side by side at the end of the content, sharing its width. Put the confirming button last. |
Keyboard
| Key | Does |
|---|---|
| Tab / Shift+Tab | cycle within it, in either form — focus is trapped |
| Escape | close and return focus to the opener |
| ↑ / ↓ | as a Drawer, move between snap points from the grabber — ↓ at the lowest one closes |
Example
The markup behind the screenshot above, lifted from src/routes/shots/ — so it
compiles, and it is exactly what produced the image.
<script lang="ts">
import { ResponsiveDialog, Button, Input, Label } from '$lib/index.js';
const uid = $props.id();
let open = $state(true);
</script>
<ResponsiveDialog bind:open title="Rename the share" description="Apps that use it keep working; only the label changes.">
<div class="flex flex-col gap-2">
<Label for="{uid}-name">Name</Label>
<Input id="{uid}-name" value="Family photos" />
</div>
{#snippet footer()}
<Button variant="outline" onclick={() => (open = false)}>Cancel</Button>
<Button onclick={() => (open = false)}>Rename</Button>
{/snippet}
</ResponsiveDialog>
Notes
- When to reach for it instead of Dialog. A plain Dialog already sits at the bottom of a phone's screen, but it is a fixed box: no grabber, no snap points, nothing to drag. Reach for this one when the content is more than a question — a form, a list to pick from — and a phone reader should be able to pull it taller or flick it away like any other bottom sheet.
breakpointis the viewport, not a container. It is a media query, so640matches Tailwind'ssm: a Drawer below it, a Dialog at and above it.- The form is chosen as it opens and kept until it closes. Crossing the breakpoint while open (a phone rotated, a window dragged narrower) changes nothing until it has closed; the next opening reads the width again. Swapping shape mid-form would rebuild the form and lose what the reader typed.
- The footer moves in the Drawer. The Drawer is its tallest self pushed
down to the current snap point, so a bar along its bottom would be off the
screen at the lower one. The actions sit at the end of the content instead,
side by side and sharing the width;
classes.footerrestyles that row. snapPointsdefaults taller than Drawer's.[0.6, 0.95]rather than a peek: a form wants room for its fields and the keyboard, and a peek that shows only the title is a step the reader has to undo.
Overlays · Dialog · Sheet · SidePanel · Drawer · Tooltip · Popover
driftwood
Layout
Actions
Forms
- Field
- Input
- FileInput
- FileList
- Textarea
- CodeEditor
- Combobox
- RadioGroup
- ColorSwatches
- NumberInput
- InlineEdit
- Label
- Select
- MultiSelect
- DatePicker
- TagsInput
- Checkbox
- Switch
- Slider
Feedback
Charts
Overlays
Navigation
Generated from the source by pnpm wiki · repository · v0.34.0



