Skip to content
Porcelana

AlertDialog

Confirmation that must be answered, for destructive actions.

Example

Example.tsx
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogTitle,
  AlertDialogTrigger,
  Button
} from "@porcelana/ui";

export default function Example() {
  return (
    <AlertDialog>
      <AlertDialogTrigger asChild>
        <Button variant="danger">Delete alarm…</Button>
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogTitle>Delete this alarm?</AlertDialogTitle>
        <AlertDialogDescription>The 06:00 weekday alarm will be removed from every device.</AlertDialogDescription>
        <AlertDialogFooter>
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction variant="danger">Delete</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
}

Import

Import
import { AlertDialogContent, AlertDialogAction, AlertDialogCancel } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app root

Props

Generated from the TypeScript types. Standard HTML attributes are passed through and not listed.

AlertDialogContent

PropTypeDefaultDescription
aria-labelstring–Defines a string value that labels the current element. @see aria-labelledby.
asChildboolean–Render the single child element instead, merging props and behaviour onto it.
centeredboolean–Keep the centered modal on phones instead of the bottom sheet.
deferPointerDownOutsideboolean–When `true`, a `'pointerdown'` event outside of the layered element will wait for the interaction's click event before dispatching, allowing third-party code to stop propagation of later events and cancel dismissal.
forceMounttrue–Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
idstring–Element id. Generated automatically when omitted.
onCloseAutoFocus((event: Event) => void)–Event handler called when auto-focusing on close. Can be prevented.
onEscapeKeyDown((event: KeyboardEvent) => void)–Event handler called when the escape key is down. Can be prevented.
onFocusOutside((event: FocusOutsideEvent) => void)–Event handler called when the focus moves outside of the `DismissableLayer`. Can be prevented.
onOpenAutoFocus((event: Event) => void)–Event handler called when auto-focusing on open. Can be prevented.

AlertDialogAction

PropTypeDefaultDescription
aria-labelstring–Defines a string value that labels the current element. @see aria-labelledby.
asChildboolean–Render the single child element instead, merging props and behaviour onto it.
disabledboolean–Prevents interaction and dims the control.
idstring–Element id. Generated automatically when omitted.
type"button" | "submit" | "reset"–Button type (defaults to "button").
variant"primary" | "soft" | "outline" | "ghost" | "danger" | nullsoftVisual style.

AlertDialogCancel

PropTypeDefaultDescription
aria-labelstring–Defines a string value that labels the current element. @see aria-labelledby.
asChildboolean–Render the single child element instead, merging props and behaviour onto it.
disabledboolean–Prevents interaction and dims the control.
idstring–Element id. Generated automatically when omitted.
type"button" | "submit" | "reset"–Button type (defaults to "button").
variant"primary" | "soft" | "outline" | "ghost" | "danger" | nullsoftVisual style.

Accessibility

  • role="alertdialog"; clicking outside doesn't close it.
  • Cancel gets focus first, so Enter never confirms by accident.

Mobile

  • Bottom sheet under 640px with full-width, 52px buttons.