Dialog
A modal in the middle of the screen, over a backdrop, with a title, an optional message, a body and actions.
Stability: experimental
Props
| Prop | Type | Default | Means |
|---|---|---|---|
title | string | The heading, and the dialog's accessible name. | |
message | string | A line of text under the title. | |
open | boolean | bindable(false) | Whether the dialog shows. Bind it with bind:open={name}; the trigger piece sets it, and Escape or a backdrop press clears it. |
dismissible | boolean | true | Whether Escape and a backdrop press close it. Without, only its actions do. |
Pieces
| Piece | Means |
|---|---|
trigger | The control that opens the dialog, such as a Button. It is told the dialog is open (aria-expanded) and gets focus back on close. |
actions | Buttons at the bottom edge, end-aligned, such as Cancel and Save. |
Children
The dialog's body, between the title and the actions, such as a form.
States
| State | Looks like |
|---|---|
closed | Not shown. Only the trigger piece shows where the dialog is written. |
opening | The backdrop fades in and the panel rises and grows into place, in 180 ms; at once with reduced motion. |
open | A surface panel up to 420px wide with a large radius and shadow, centred over the scrim; it scrolls when taller than the window. |
Accessibility
| role | dialog with aria-modal="true" |
| name | The title prop (aria-label). |
| focus | On open, focus moves to the first focusable element in the body, else the first action. Tab and Shift+Tab stay inside, wrapping at the ends; the page behind is inert and does not scroll. On close, focus returns to the control that opened it. |
| keyboard | Escape closes it (unless dismissible is false). |
| notes | The trigger piece's control carries aria-haspopup="dialog", aria-expanded and aria-controls. |
Theme tokens
color.scrim color.surface color.ink color.muted shadow.lg radius.lg space.2 space.3 space.4 space.6 text.heading text.body
Example
<Dialog title="Edit name" bind:open={editing}><TextField label="Name" bind:value={name} /><piece name="actions"><Button label="Save" onPress={save} /></piece></Dialog>