Dialog
A modal window presenting content or seeking user input without navigating away from the current context.
Structure
Controlled Usage
If you want to control or be aware of the open
state of the dialog from outside of the component, you can bind to the open
prop.
API Reference
The root component used to set and manage the state of the dialog.
Property | Type | Description |
---|---|---|
open bindable prop | boolean | Whether or not the dialog is open. Default: false |
onOpenChange | function | A callback function called when the open state changes. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
The element which opens the dialog on press.
Property | Type | Description |
---|---|---|
ref bindable prop | HTMLButtonElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See delegation docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-dialog-trigger | —— | Present on the trigger. |
The content displayed within the dialog modal.
Property | Type | Description |
---|---|---|
onEscapeKeydown | function | Callback fired when an escape keydown event occurs in the floating content. You can call Default: undefined |
escapeKeydownBehavior | enum | The behavior to use when an escape keydown event occurs in the floating content. Default: close |
onInteractOutside | function | Callback fired when an outside interaction event completes, which is either a Default: undefined |
onInteractOutsideStart | function | Callback fired when an outside interaction event starts, which is either a Default: undefined |
onFocusOutside | function | Callback fired when focus leaves the dismissable layer. You can call Default: undefined |
interactOutsideBehavior | enum | The behavior to use when an interaction occurs outside of the floating content. Default: close |
onMountAutoFocus | function | Event handler called when auto-focusing the content as it is mounted. Can be prevented. Default: undefined |
onDestroyAutoFocus | function | Event handler called when auto-focusing the content as it is destroyed. Can be prevented. Default: undefined |
forceMount | boolean | Whether or not to forcefully mount the content. This is useful if you want to use Svelte transitions or another animation library for the content. Default: false |
preventOverflowTextSelection | boolean | When Default: true |
preventScroll | boolean | When Default: true |
ref bindable prop | HTMLDivElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See delegation docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-state | enum | The state of the dialog. |
data-dialog-content | —— | Present on the content. |
An overlay which covers the body when the dialog is open.
Property | Type | Description |
---|---|---|
forceMount | boolean | Whether or not to forcefully mount the content. This is useful if you want to use Svelte transitions or another animation library for the content. Default: false |
ref bindable prop | HTMLDivElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See delegation docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-state | enum | The state of the dialog. |
data-dialog-overlay | —— | Present on the overlay. |
A portal which renders the dialog into the body when it is open.
Property | Type | Description |
---|---|---|
to | union | Where to render the content when it is open. Defaults to the body. Can be disabled by passing Default: body |
disabled | boolean | Whether the portal is disabled or not. When disabled, the content will be rendered in its original DOM location. Default: false |
children | Snippet | The children content to render. Default: undefined |
A button used to close the dialog.
Property | Type | Description |
---|---|---|
ref bindable prop | HTMLButtonElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See delegation docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-dialog-close | —— | Present on the close button. |
An accessibile title for the dialog.
Property | Type | Description |
---|---|---|
level | union | The heading level of the title. Default: 3 |
ref bindable prop | HTMLDivElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See delegation docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-dialog-title | —— | Present on the title. |
An accessibile description for the dialog.
Property | Type | Description |
---|---|---|
ref bindable prop | HTMLDivElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See delegation docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-dialog-description | —— | Present on the description. |