Components ds-dialog
Dialog
Modal dialog on the native dialog element. The page behind turns inert and stops scrolling while it is open, Escape or a click on the backdrop closes it, and focus returns to the control that opened it.
Live playground
watchlist: Rate cuts
events: none yet
Interactive props
Usage example
<button @click=${() => dialog.open()}>Rename watchlist</button>
<ds-dialog
label="Rename watchlist"
style="--ds-dialog-backdrop-blur: 4px; --ds-dialog-width: 28rem"
@ds-close=${this.onClose}
>
<!-- method="dialog" cannot reach the dialog in the shadow root, so the
submit handler calls dialog.close() itself. -->
<form @submit=${this.onSubmit}>
<h2>Rename watchlist</h2>
…
<button type="button" @click=${() => dialog.close()}>Cancel</button>
<button type="submit">Save</button>
</form>
</ds-dialog>
Keyboard
| Key | Result |
|---|---|
| Tab / Shift+Tab | Moves through the dialog's controls, wrapping at either end. The page behind is inert, so focus never reaches it. |
| Escape | Closes the dialog and returns focus to the trigger. |
API Reference
| Member | Kind | Description |
|---|---|---|
| label | property | Accessible name, announced when the dialog opens. |
| isOpen | getter | Whether the dialog is open. |
| open() | method | Shows the dialog with showModal(). Focus moves to a slotted element with autofocus, else the first focusable one. |
| close() | method | Closes the dialog and returns focus to the element focused before it opened. |
| ds-open | event | Fires after the dialog opens. |
| ds-close | event | Fires after the dialog closes, by close(), Escape or a click on the backdrop. |
| overlay | part | The native dialog, a transparent layer over the viewport. |
| panel | part | The surface around the slotted content. |
| --ds-dialog-backdrop-color | css | Backdrop fill. Defaults to the page background at 80%. |
| --ds-dialog-backdrop-blur | css | Blur applied to the page behind. Defaults to 4px. |
| --ds-dialog-width | css | Maximum width of the panel. Defaults to 32rem. |