AlertDialog
A confirmation that holds focus until the person decides.
3 drafts left
Source
<script lang="ts">
import 'portal-bits/styles.css';
import 'portal-bits/tokens.css';
import type { Snippet } from 'svelte';
let { children }: { children: Snippet } = $props();
</script>
{@render children()}
<script lang="ts">
import AlertDialogExample from './AlertDialogExample.svelte';
</script>
<AlertDialogExample tone={"danger"} />
<script lang="ts">
import { AlertDialog } from 'portal-bits';
let { tone = 'danger' }: { tone?: 'neutral' | 'danger' } = $props();
let drafts = $state(3);
</script>
<div class="stack">
<AlertDialog
title={tone === 'danger' ? 'Delete this draft?' : 'Publish this draft?'}
description={tone === 'danger'
? 'The draft and its comments are removed for everyone. This cannot be undone.'
: 'Everyone with the link can read it. You can unpublish later.'}
confirmLabel={tone === 'danger' ? 'Delete draft' : 'Publish'}
{tone}
onConfirm={() => (drafts = Math.max(0, drafts - 1))}
>
{#snippet trigger()}{tone === 'danger' ? 'Delete draft' : 'Publish draft'}{/snippet}
</AlertDialog>
<p aria-live="polite">{drafts} {drafts === 1 ? 'draft' : 'drafts'} left</p>
</div>
<style>
.stack {
display: grid;
justify-items: center;
gap: 12px;
}
p {
margin: 0;
}
</style>
API reference
These tables list the props and snippets that AlertDialog declares. Attributes passed through to an element or primitive are listed under Forwarded attributes, not here.
Props
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
open | boolean | false | No | Bindable | Whether the dialog is open. |
title | string | None | Yes | One-way | The question. It names the dialog. |
description | string | None | Yes | One-way | What happens when the person confirms. |
confirmLabel | string | None | Yes | One-way | The confirm button text. Name the action. |
cancelLabel | string | Cancel | No | One-way | The cancel button text. |
tone | 'neutral' | 'danger' | neutral | No | One-way | Danger paints the confirm button red. |
onConfirm | () => void | None | No | One-way | Runs when the person confirms. The dialog then closes. |
triggerLabel | string | None | No | One-way | Sets `aria-label` on the trigger. |
triggerClass | string | Secondary 40px button | No | One-way | Replaces the trigger classes. |
theme | 'light' | 'dark' | light | No | One-way | Theme scope for the portaled content. Portaled content does not inherit the page scope. |
Snippets
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
trigger | Snippet | None | No | One-way | The trigger content. Without it, bind `open`. |
Forwarded attributes
None. AlertDialog forwards no attributes.
The primitive underneath is a Bits UI peer dependency. Its own options are documented in the Bits UI Alert Dialog documentation. Only the props listed on this page are part of the AlertDialog contract. No data attributes are documented as stable.
Limits
- Escape and Cancel close it. A click outside does not, unlike Dialog.
- Cancel takes focus when it opens, so the safe choice is the default.
- The danger fill is an adaptation that uses the error token.