Overlays

Alert dialog

Asks before something important happens, such as deleting. It waits for an answer: a press outside doesn't close it.

Installation

npx sinaui add alert-dialog

Examples

Confirm a delete

The button waits while it works. The first try fails here, to show the dialog staying open with the reason; try again and it goes through.

Delete this manuscript?

The Book of Optics and its 214 scanned pages will be removed for everyone. This can't be undone.

<script lang="ts">
	import AlertDialog from '#lib/ui/AlertDialog.svelte';
	import Button from '#lib/ui/Button.svelte';
	import { toast } from '#lib/ui/toast/index.js';

	let open = $state(false);
	let attempts = 0;
	// Stands in for a request: the first try fails, so the error state can be seen; the second succeeds.
	const remove = () =>
		new Promise<void>((done, fail) =>
			setTimeout(() => {
				if (attempts++ % 2 === 0) fail(new Error("The library couldn't be reached. Try again."));
				else {
					done();
					toast.success('Manuscript deleted');
				}
			}, 900)
		);
</script>

<Button variant="danger" onclick={() => (open = true)}>Delete manuscript</Button>
<AlertDialog
	bind:open
	title="Delete this manuscript?"
	description="The Book of Optics and its 214 scanned pages will be removed for everyone. This can't be undone."
	confirmLabel="Delete"
	onconfirm={remove}
/>

Writing it

  • Ask a question that names the action: “Delete this manuscript?”
  • Say what happens and whether it can be undone.
  • Label the button with the verb (“Delete”), never “OK” or “Yes”.

Props

PropTypeDefault
openboolean (bindable)false
title, descriptionstringrequired
confirmLabelstringrequired
cancelLabelstring'Cancel'
tone'danger' | 'primary''danger'
onconfirm() => void | Promise<void>; throw to keep it open with the messagerequired

Accessibility

  • An alert dialog: the question and description are read as soon as it opens.
  • Focus starts on Cancel, so a stray Enter never confirms.
  • Escape cancels, except while the action is under way. Focus returns to the button that opened it.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme