Skip to content

Overlay

AlertDialog

Confirmation modal for destructive or important actions.

import { AlertDialog } from '@var-ui/react';

AlertDialog

Modal confirmation for important or destructive actions. AlertDialog is the compound Root: a Dialog with role="alertdialog" and backdrop dismissal off (AlertDialog.Trigger, Popup, Header, Title, Description, Actions, Close; the popup is a native <dialog role="alertdialog">, so there is no Backdrop part). The cancel/confirm arrangement is a recipe you copy, not a preset: confirm is just your button inside AlertDialog.Close, so Cancel and Escape never run it. The trigger must be a button — there is no render prop.

State attributes, exit animation, and onOpenChange details are documented in Overlay lifecycle.

Examples

Default

Destructive confirms use tone="danger" and autofocus Cancel so Enter does not confirm by accident. autoFocus works on a Button; on a plain host element use the native autofocus attribute (React’s autoFocus runs before the dialog is shown and does nothing there).

Demo.tsxTSX
import { AlertDialog, Button } from '@var-ui/react';

<AlertDialog>
  <AlertDialog.Trigger>
    <Button>Delete</Button>
  </AlertDialog.Trigger>
  <AlertDialog.Popup>
    <AlertDialog.Header>
      <AlertDialog.Title>Delete item?</AlertDialog.Title>
    </AlertDialog.Header>
    <AlertDialog.Description>This cannot be undone.</AlertDialog.Description>
    <AlertDialog.Actions>
      <AlertDialog.Close>
        <Button autoFocus>Cancel</Button>
      </AlertDialog.Close>
      <AlertDialog.Close>
        <Button tone="danger" appearance="solid" onClick={() => {}}>
          Delete
        </Button>
      </AlertDialog.Close>
    </AlertDialog.Actions>
  </AlertDialog.Popup>
</AlertDialog>

Confirm pattern

Non-destructive confirms use tone="accent" and appearance="solid". Change the button labels to match the task. To confirm asynchronously, drop the confirm AlertDialog.Close, run your work in the button’s onClick, then close with controlled open.

Demo.tsxTSX
import { AlertDialog, Button } from '@var-ui/react';

<AlertDialog>
  <AlertDialog.Trigger>
    <Button>Publish</Button>
  </AlertDialog.Trigger>
  <AlertDialog.Popup>
    <AlertDialog.Header>
      <AlertDialog.Title>Publish post?</AlertDialog.Title>
    </AlertDialog.Header>
    <AlertDialog.Description>Your draft will become visible to everyone with the link.</AlertDialog.Description>
    <AlertDialog.Actions>
      <AlertDialog.Close>
        <Button>Keep editing</Button>
      </AlertDialog.Close>
      <AlertDialog.Close>
        <Button tone="accent" appearance="solid" onClick={() => {}}>
          Publish
        </Button>
      </AlertDialog.Close>
    </AlertDialog.Actions>
  </AlertDialog.Popup>
</AlertDialog>

Props

Accessibility

Renders as a native modal <dialog role="alertdialog">; the rest of the page is inert. Destructive flows autofocus Cancel so Enter does not immediately confirm. Escape and the cancel button dismiss without calling onConfirm. Prefer a clear title and short description that name the irreversible consequence.