Confirm dialog
The replacement for window.confirm: a focused alert dialog, or confirm() as a promise.
import { ConfirmDialog, ConfirmHost, confirm } from "@arcadia/ui"confirm() resolves true on confirm and false on cancel or Esc. Requests queue, one dialog at a time, and render through one <ConfirmHost/> mounted at the app root; without it, confirm() rejects. Say what happens on the button ("Delete", "Discard"), never "OK".
Confirm, Dialog or Tray? Confirm only to stop something that can't be undone. A Dialog is for a task with its own controls. A question the product asks during work belongs in a Tray docked to the composer, where it doesn't block the page.
Examples
An alertdialog, named by its title and described by its description, that ignores clicks outside. Initial focus lands on Cancel for danger and on the confirm button otherwise, so a stray Enter never deletes anything. Focus returns to the button that asked.
- Enter
- Confirms, unless focus is on another button
- Esc
- Cancels
- Tab
- Moves between Cancel and the action
ConfirmDialog
open- boolean
defaultOpen- booleanDefault false
onOpenChange- (open: boolean) => void
onOpenChangeComplete- (open: boolean) => void
- Called after the close animation.
onConfirm- () => unknown
- Runs on confirm. A returned promise shows the loading state; a rejection keeps the dialog open and shows its message. The dialog closes when it resolves.
onCancel- () => void
loading- boolean
- Controlled loading state (overrides the async one).
error- ReactNode
- Controlled error message (overrides a caught rejection).
modal- booleanDefault true
falsefor inline previews.initialFocus- ComponentProps<typeof DialogContent>["initialFocus"]
- Override the initial focus (default: Cancel for
danger, else the confirm button;falseleaves focus where it is, for inline previews). titlerequired- ReactNode
description- ReactNode
confirmLabel- stringDefault "Confirm"
- Say what happens: "Delete", "Discard changes".
cancelLabel- stringDefault "Cancel"
tone- "neutral" | "danger"Default "neutral"
children- ReactNode
- Extra content between the description and the actions (a "don't ask again" switch).
titlerequired- ReactNode
description- ReactNode
confirmLabel- stringDefault "Confirm"
- Say what happens: "Delete", "Discard changes".
cancelLabel- stringDefault "Cancel"
tone- "neutral" | "danger"Default "neutral"