Skip to content
Klarhimmel UI

Alert dialog

npx shadcn add @klarhimmel/alert-dialog @klarhimmel/button

Examples

  • Destructive

  • Confirm

  • Controlled

DetailsAbout, usage, props and more

A confirmation that cannot be dismissed by accident. Built on Dialog.

When to use

  • Use for

    A decision with consequences that must not be taken by accident: delete, send, publish.

  • Not for

    Information. Use Banner. A task with fields. Use Dialog.

  • Pairs with

    Button, a short sentence.

Preview

Nothing deleted yet.

alert-dialog.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { AlertDialog } from '@/components/klarhimmel/ui/alert-dialog';
import { Button } from '@/components/klarhimmel/ui/button';

export default function Example() {
  return (
    <Theme theme="brand">
      <AlertDialog
        destructive
        trigger={<Button variant="secondary">Delete room</Button>}
        title="Delete the Garden room?"
        description="Its bookings are cancelled. This cannot be undone."
        confirmLabel="Delete room"
        onConfirm={() => console.log('deleted')}
      />
    </Theme>
  );
}

Import

Import

import { AlertDialog } from '@/components/klarhimmel/ui/alert-dialog';
Files
alert-dialog.tsx, button.tsx, in components/klarhimmel/ui/. With it: dialog, editing, theme, utils. npm: radix-ui.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
Limit
Overlays render into the Theme root with position: fixed. A transform on an ancestor re-parents fixed (a dialog centres in the wrapper) and overflow: hidden clips menus. Render <Theme> at the app root, outside any transformed wrapper.

Props

PropTypeDefaultDescription
openboolean-Same as Dialog.
defaultOpenboolean-
onOpenChange(open: boolean) => void-Same as Dialog.
triggerReactNode-The element that opens it (a Button). Omit for a controlled dialog.
titlestringrequiredRequired: the question, written as one ("Delete the Garden room?").
descriptionstringrequiredWhat happens if they say yes. Read out with the title.
confirmLabelstringrequiredThe label of the yes button. Name the action ("Delete room"), never "OK".
cancelLabelstring'Cancel'The label of the safe button.
onConfirm() => voidrequiredCalled when the confirm button is pressed; the dialog closes after it.
destructiveboolean-Styles the confirm button in the danger colour.

Accessibility

KeyDoes
Tab / Shift+TabCycles inside the dialog
EscapeCancels and returns focus to the trigger
Enter / SpaceActivates the focused button

A click outside does not close it. Write the confirm label as the action, not "OK".

Accessibility