Skip to contentKino
Skip to Content

Alert dialog

A question that needs an answer before something that can’t easily be undone. A press outside makes it swell instead of closing it.

npx shadcn add https://kinoui.com/r/alert-dialog.json
Share on

Examples

Default

It rises into the centre like the Dialog. A press outside makes it swell instead of closing it, and focus starts on Cancel.

Badge

With variant='badge' the question sits centred under an icon in AlertDialogMedia, and the answers stack.

An action that takes time

Return a promise from onClick: the dialog stays open with a spinner until it settles, and stays open when it rejects. This one fails once.

Type to confirm

For the highest stakes, ask for the name in AlertDialogBody, start focus there with initialFocus, and allow the action once it matches.

Controlled

Opened with open, it needs no trigger, as when a menu item asks first. Focus goes back to what had it before.

Installation

npx shadcn@latest add https://kinoui.com/r/alert-dialog.json
Files
lib/reduce-motion.tslib/resize.tslib/scroll.tslib/panel.tsxlib/refs.tslib/swap.tsxcomponents/kino/spinner.tsxcomponents/kino/button.tsxcomponents/kino/dialog.tsxlib/refuse.tscomponents/kino/alert-dialog.tsx
Packages
@base-ui/reactclass-variance-authority

New to Kino? Installation covers what your project needs first and the @kino namespace.

API reference

AlertDialog

PropTypeDefaultDescription
openbooleanNoneWhether it is open, when you hold the state.
onOpenChange(open, details) => voidNoneCalled when it opens or closes.

AlertDialogContent

PropTypeDefaultDescription
variant'default''badge''default'The badge variant centres the header under its media and stacks the actions, on a narrower box.
initialFocusRefObjectfunctionbooleanCancelWhat takes focus when it opens, such as a field to type a name into.
finalFocusRefObjectfunctionbooleanNoneWhat takes focus when it closes, in place of the trigger. Set it when the action removes the trigger.
containerHTMLElementShadowRootRefObjectdocument.bodyWhere it renders, as with the Dialog.

AlertDialogMedia

PropTypeDefaultDescription
variant'default''destructive''default'Its tint.

AlertDialogAction

PropTypeDefaultDescription
onClick(event) => void(event) => PromiseNoneWhen it returns, the dialog closes. When it returns a promise, the dialog stays open and the button shows a spinner until the promise settles: it closes once it resolves, and stays open when it rejects. A rejection isn’t logged: catch it to show why in AlertDialogError.

Data attributes

AttributeOnDescription
data-refusedAlertDialogContentSet while it answers a press outside.
data-variantAlertDialogContentdefault or badge.

Accessibility

  • It is an alertdialog: focus moves into it and stays there, and a screen reader reads the title and the description when it opens.
  • Focus starts on Cancel, the safe answer, so Enter right after it opens does nothing that can’t be undone. When it closes, focus goes back to the trigger; set finalFocus when the action removes it.
  • A press outside doesn’t close it. Escape does, except while an action runs, and so does Cancel.
  • While an action runs, the action button keeps focus and is announced as busy, and Cancel waits. An error in AlertDialogError is announced, and focus stays on the action, ready to try again.
  • When the system asks for less motion, it fades in and out where it stands, and at a press outside Cancel lights up instead of the dialog swelling.