AlertDialog wraps a small Modal with a confirm / cancel pair. Bind open and handle onYes / onCancel in your app. Interactive open state belongs in route or example fences — not top-level markdown $state (SSR).
Setup
<script lang="ts">
import { AlertDialog, Button } from '.';
</script> Default
Bind open and handle onYes / onCancel:
<script lang="ts">
import { AlertDialog, Button } from '.';
let open = $state(false);
</script>
<Button color="red" onclick={() => (open = true)}>Delete item</Button>
<AlertDialog
bind:open
message="Are you sure you want to delete this item? This action cannot be undone."
onYes={() => (open = false)}
onCancel={() => (open = false)}
/> Live confirm dialogs need local state — copy the example above into your route.
Custom confirm label and icon
<script lang="ts">
import { AlertDialog, Button } from '.';
let open = $state(false);
</script>
<Button color="red" onclick={() => (open = true)}>Archive</Button>
<AlertDialog
bind:open
message="Archive this project? You can restore it later."
confirmText="Yes, archive"
icon="mdi:archive-outline"
iconColor="text-amber-500"
onYes={() => (open = false)}
onCancel={() => (open = false)}
/> Busy / disable confirm
While an async action runs, set busy (shows a spinner on the confirm button) and optionally disableYes.
<script lang="ts">
import { AlertDialog, Button } from '.';
let open = $state(false);
let busy = $state(false);
async function confirm() {
busy = true;
await new Promise((r) => setTimeout(r, 800));
busy = false;
open = false;
}
</script>
<Button color="red" onclick={() => (open = true)}>Delete</Button>
<AlertDialog
bind:open
{busy}
message="Deleting…"
onYes={confirm}
onCancel={() => (open = false)}
/> Form submit confirm
Set buttonType="submit" when the dialog sits inside a form and the confirm button should submit.
<script lang="ts">
import { AlertDialog } from '.';
let open = $state(false);
</script>
<form method="POST">
<AlertDialog
bind:open
buttonType="submit"
message="Submit this form?"
onYes={() => {}}
onCancel={() => (open = false)}
/>
</form> Props
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | false | Bindable visibility |
message | string | '' | Body copy under the icon |
icon | string | 'line-md:alert-circle' | Iconify icon id |
iconColor | string | '' | Classes on the icon (e.g. text-red-500) |
confirmText | string | "Yes, I'm sure" | Confirm button label |
buttonType | 'submit' | 'button' | 'reset' | 'button' | Confirm button type |
disableYes | boolean | false | Disable confirm without busy UI |
busy | boolean | false | Disable both buttons + spinner on confirm |
dismissable | boolean | true | Allow modal dismiss (close / Esc / outside) |
onYes | () => void | — | Confirm callback (required) |
onCancel | () => void | — | Cancel callback (required) |