Skip to content
Overlays Core Stable

AlertDialog

.md

A confirmation dialog for consequential, hard-to-undo actions — fixed confirm/cancel actions, never dismissed by an outside click

Available for Svelte 5, React, and Vue 3.

Preview

Installation

pnpm add fancy-ui-svelte
import { AlertDialog } from "fancy-ui-svelte";

Usage

svelte
<script lang="ts">
	import { AlertDialog } from "fancy-ui-svelte";
	import { Button } from "fancy-ui-svelte";

	let status = $state("");
</script>

{#snippet trigger()}
	<Button variant="destructive">Delete project</Button>
{/snippet}

<AlertDialog
	sound
	{trigger}
	title="Delete this project?"
	description="This action is irreversible. All data will be lost."
	confirmLabel="Delete"
	onConfirm={() => (status = "Project deleted.")}
	onCancel={() => (status = "Cancelled.")}
/>

{#if status}
	<p class="text-muted-foreground mt-2 text-[12px]">{status}</p>
{/if}

Examples

Basic Usage

A destructive delete confirmation with a trigger.

Controlled Open

Non-bound open plus onOpenChange, triggered from a list row.

Custom Labels

A non-delete use case — signing out of every device.

Props

PropTypeDefaultDescription
open booleanfalseWhether the alert dialog is open; bindable
onOpenChange (open: boolean) => void-Fires whenever open changes — Confirm, Cancel, or Escape
title string-The heading. Omitted entirely (not just visually) when not given
description string-The warning copy under the title. Same omission rule as title
confirmLabel string"Confirm"Label of the destructive action
cancelLabel string"Cancel"Label of the safe action
onConfirm () => void-Called when the destructive action is activated, before the surface closes
onCancel () => void-Called when the safe action is activated, and also when Escape closes it
initialFocus HTMLElement | null-Element to focus once the surface opens; defaults to the Cancel button
class string-Additional CSS classes for the panel
ref HTMLDivElement | nullnullBindable reference to the panel element
sound booleanfalsePlays open on the trigger, select on a confirmed action and close on Cancel or Escape, once the user has enabled sound

Slots

SlotDescription
trigger Optional trigger; renders in place and opens the surface on activation