Installation
Barrel
import { Dialog } from 'kumo-svelte'; Granular
import { Dialog } from 'kumo-svelte/components/dialog'; Usage
<script lang="ts">
import { Dialog, Button } from "kumo-svelte";
let open = $state(false);
</script>
<Dialog bind:open title="Dialog Title" description="Dialog content goes here.">
{#snippet trigger(props)}
<Button {...props}>Open</Button>
{/snippet}
<div class="flex justify-end gap-2">
<Button variant="secondary" onclick={() => (open = false)}>Cancel</Button>
</div>
</Dialog> Dialog vs Alert Dialog
The Dialog component supports two ARIA roles to properly convey semantic meaning to assistive technologies:
| Role | Use Case | Behavior |
|---|---|---|
role="dialog" (default) | General-purpose modals, forms, content display | Dismissible by default |
role="alertdialog" | Destructive actions, confirmations, critical warnings | Requires explicit user acknowledgment |
Examples
Basic Dialog
Sizes
The size prop controls the fixed width of the dialog on desktop. Content that
overflows the dialog width will scroll horizontally within the dialog rather
than stretching it.
Alert Dialog (role="alertdialog")
For destructive or confirmation dialogs, use role="alertdialog" on Dialog. This provides proper accessibility semantics by rendering the
dialog with role="alertdialog" instead of role="dialog".
When to use role="alertdialog":
- Destructive actions (delete, discard, remove)
- Confirmation flows requiring explicit user acknowledgment
- Actions that cannot be undone
- Critical warnings or errors
Confirmation Dialog (with disablePointerDismissal)
For confirmation dialogs that should not be dismissed by clicking outside, use disablePointerDismissal on Dialog. This can be combined with role="alertdialog" for proper accessibility.
With Actions
Custom Max Width
Consumer max-width utilities such as max-w-lg should cap the dialog on
desktop, even when the dialog contains wide intrinsic content.
With Select
Dialog containing a Select dropdown.
With Combobox
Dialog containing a Combobox for searchable selection.
With Dropdown
Dialog containing a Dropdown menu.
API Reference
Dialog
The main dialog container that renders the modal overlay and popup.
| Prop | Type | Default | Description |
|---|---|---|---|
| role | "dialog" | "alertdialog" | "dialog" | The ARIA role for the dialog. Use "alertdialog" for destructive or
confirmation flows. |
| disablePointerDismissal | boolean | false | When true, prevents the dialog from being dismissed by clicking outside. |
| Prop | Type | Default | Description |
|---|---|---|---|
| class | string | - | Additional classes merged onto the dialog content. |
| children | Snippet | - | Dialog content, typically title, description, close, and action buttons. |
| container | HTMLElement | string | document.body | Portal container for custom roots or Shadow DOM. |
| description | string | - | Description rendered under the dialog title. |
| disablePointerDismissal | boolean | false | When true, prevents the dialog from being dismissed by clicking outside. |
| open | boolean | false | Controlled open state. Supports bind:open. |
| role | 'dialog' | 'alertdialog' | "dialog" | ARIA role for the dialog. |
| size | 'sm' | 'base' | 'lg' | 'xl' | "base" | Fixed dialog width preset: sm (288px), base (384px), lg (512px), or xl (768px). |
| style | string | - | Inline styles for the dialog content. |
| title | string | - | Title rendered as the accessible dialog heading. |
| trigger | Snippet<[Record<string, unknown>]> | - | Trigger snippet that receives props for opening the dialog. |