AlertDialog

A modal that interrupts to confirm something consequential.

Usage

import { AlertDialog } from "@hoplallc/ui/alert-dialog";
<AlertDialog.Root>
	<AlertDialog.Trigger render={<Button variant="outline" />}>Cancel</AlertDialog.Trigger>
	<AlertDialog.Content size="sm">
		<AlertDialog.Header>
			<AlertDialog.Media><WarningIcon className="text-destructive" /></AlertDialog.Media>
			<AlertDialog.Title>Cancel this project?</AlertDialog.Title>
			<AlertDialog.Description>The freelancer will be notified.</AlertDialog.Description>
		</AlertDialog.Header>
		<AlertDialog.Footer>
			<AlertDialog.Cancel>Keep project</AlertDialog.Cancel>
			<AlertDialog.Action variant="destructive">Cancel project</AlertDialog.Action>
		</AlertDialog.Footer>
	</AlertDialog.Content>
</AlertDialog.Root>

A modal that asks one question and will not be dismissed by clicking away. That is the whole difference from Dialog: an alert dialog is for a decision with consequences, so the escape routes are deliberate buttons rather than the backdrop. If you are building the common destructive confirmation, ConfirmDialog is this component with the title, buttons and open state already wired — reach for that first and come here when the layout needs to be your own.

Recipes

size takes default or sm; sm fits a question whose answer is one line.

Put the consequence in the title, not the control: "Delete this project?" tells someone what they are about to do, "Are you sure?" makes them guess. The confirm button should name the action too — Delete project, never OK.

API

AlertDialog.Root

PropTypeDefault
actionsRefRefObject<DialogRootActions | null>—A ref to imperative actions.
childrenPayloadChildRenderFunction<unknown> | ReactNode—The content of the dialog. This can be a regular React node or a render function that receives the payload of the active trigger.
defaultOpenboolean—Whether the dialog is initially open. To render a controlled dialog, use the open prop instead.
defaultTriggerIdstring | null—ID of the trigger that the dialog is associated with. This is useful in conjunction with the defaultOpen prop to create an initially open dialog.
handleAlertDialogHandle<unknown>—A handle to associate the alert dialog with a trigger. If specified, allows external triggers to control the alert dialog's open state. Can be created with the AlertDialog.createHandle() method.
onOpenChange((open: boolean, eventDetails: AlertDialogRootChangeEventDetails) => void)—Event handler called when the alert dialog is opened or closed.
onOpenChangeComplete((open: boolean) => void)—Event handler called after any animations complete when the dialog is opened or closed.
openboolean—Whether the dialog is currently open.
triggerIdstring | null—ID of the trigger that the dialog is associated with. This is useful in conjunction with the open prop to create a controlled dialog. There's no need to specify this prop when the dialog is uncontrolled (that is, when the open prop is not set).

Plus the DOM props of the element it renders. Source: alert-dialog/components/alert-dialog-root.tsx.

AlertDialog.Action

PropTypeDefault
size"default" | "icon" | "icon-lg" | "icon-sm" | "icon-xs" | "lg" | "sm" | "xs""default"Height and horizontal padding. The icon-* set is square, for a button whose entire content is one icon — give those an aria-label.
variant"brand" | "default" | "destructive" | "ghost" | "highlight" | "link" | "outline" | "primary" | "secondary""default"Weight of the action. default is the one thing the page exists for, at most one per view; secondary an equal-weight alternative; outline for toolbars and anything that repeats in a row; ghost inside dense surfaces; destructive for what cannot be undone; link for an action that reads as navigation.
exitExit—Inside a <Presence>: plays this child's way out before it unmounts.
classNamestring | ((state: DialogCloseState) => string | undefined)—CSS class applied to the element, or a function that returns a class based on the component's state.
nativeButtonboolean—Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
renderComponentRenderFn<HTMLProps, DialogCloseState> | ReactElement<unknown, string | JSXElementConstructor<any>>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleCSSProperties | ((state: DialogCloseState) => CSSProperties | undefined)—Style applied to the element, or a function that returns a style object based on the component's state.

Plus the DOM props of the element it renders. Source: alert-dialog/components/alert-dialog-action.tsx.

AlertDialog.Cancel

PropTypeDefault
size"default" | "icon" | "icon-lg" | "icon-sm" | "icon-xs" | "lg" | "sm" | "xs""default"Height and horizontal padding. The icon-* set is square, for a button whose entire content is one icon — give those an aria-label.
variant"brand" | "default" | "destructive" | "ghost" | "highlight" | "link" | "outline" | "primary" | "secondary""outline"Weight of the action. default is the one thing the page exists for, at most one per view; secondary an equal-weight alternative; outline for toolbars and anything that repeats in a row; ghost inside dense surfaces; destructive for what cannot be undone; link for an action that reads as navigation.
exitExit—Inside a <Presence>: plays this child's way out before it unmounts.
classNamestring | ((state: DialogCloseState) => string | undefined)—CSS class applied to the element, or a function that returns a class based on the component's state.
nativeButtonboolean—Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
renderComponentRenderFn<HTMLProps, DialogCloseState> | ReactElement<unknown, string | JSXElementConstructor<any>>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleCSSProperties | ((state: DialogCloseState) => CSSProperties | undefined)—Style applied to the element, or a function that returns a style object based on the component's state.

Plus the DOM props of the element it renders. Source: alert-dialog/components/alert-dialog-cancel.tsx.

AlertDialog.Close

PropTypeDefault
exitExit—Inside a <Presence>: plays this child's way out before it unmounts.
classNamestring | ((state: DialogCloseState) => string | undefined)—CSS class applied to the element, or a function that returns a class based on the component's state.
nativeButtonboolean—Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
renderComponentRenderFn<HTMLProps, DialogCloseState> | ReactElement<unknown, string | JSXElementConstructor<any>>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleCSSProperties | ((state: DialogCloseState) => CSSProperties | undefined)—Style applied to the element, or a function that returns a style object based on the component's state.

Plus the DOM props of the element it renders. Source: alert-dialog/components/alert-dialog-close.tsx.

AlertDialog.Content

PropTypeDefault
size"default" | "sm""default"Width of the panel. sm suits a one-line confirmation.
exitExit—Inside a <Presence>: plays this child's way out before it unmounts.
classNamestring | ((state: DialogPopupState) => string | undefined)—CSS class applied to the element, or a function that returns a class based on the component's state.
finalFocusboolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => void | boolean | HTMLElement | null)—Determines the element to focus when the dialog is closed.
initialFocusboolean | RefObject<HTMLElement | null> | ((openType: InteractionType) => void | boolean | HTMLElement | null)—Determines the element to focus when the dialog is opened. By default, focus moves to the first tabbable element inside the popup, except when the dialog is opened by touch — then the popup itself is focused to avoid opening the virtual keyboard.
renderComponentRenderFn<HTMLProps, DialogPopupState> | ReactElement<unknown, string | JSXElementConstructor<any>>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleCSSProperties | ((state: DialogPopupState) => CSSProperties | undefined)—Style applied to the element, or a function that returns a style object based on the component's state.

Plus the DOM props of the element it renders. Source: alert-dialog/components/alert-dialog-content.tsx.

AlertDialog.Description

PropTypeDefault
exitExit—Inside a <Presence>: plays this child's way out before it unmounts.
classNamestring | ((state: DialogDescriptionState) => string | undefined)—CSS class applied to the element, or a function that returns a class based on the component's state.
renderComponentRenderFn<HTMLProps, DialogDescriptionState> | ReactElement<unknown, string | JSXElementConstructor<any>>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleCSSProperties | ((state: DialogDescriptionState) => CSSProperties | undefined)—Style applied to the element, or a function that returns a style object based on the component's state.

Plus the DOM props of the element it renders. Source: alert-dialog/components/alert-dialog-description.tsx.

AlertDialog.Footer

PropTypeDefault
exitExit—Inside a <Presence>: plays this child's way out before it unmounts.
renderComponentRenderFn<HTMLProps, {}> | ReactElement<unknown, string | JSXElementConstructor<any>>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Plus every <div> prop. Source: alert-dialog/components/alert-dialog-footer.tsx.

AlertDialog.Header

PropTypeDefault
exitExit—Inside a <Presence>: plays this child's way out before it unmounts.
renderComponentRenderFn<HTMLProps, {}> | ReactElement<unknown, string | JSXElementConstructor<any>>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Plus every <div> prop. Source: alert-dialog/components/alert-dialog-header.tsx.

AlertDialog.Media

PropTypeDefault
exitExit—Inside a <Presence>: plays this child's way out before it unmounts.
renderComponentRenderFn<HTMLProps, {}> | ReactElement<unknown, string | JSXElementConstructor<any>>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Plus every <div> prop. Source: alert-dialog/components/alert-dialog-media.tsx.

AlertDialog.Overlay

PropTypeDefault
exitExit—Inside a <Presence>: plays this child's way out before it unmounts.
classNamestring | ((state: DialogBackdropState) => string | undefined)—CSS class applied to the element, or a function that returns a class based on the component's state.
forceRenderboolean—Whether the backdrop is forced to render even when nested.
renderComponentRenderFn<HTMLProps, DialogBackdropState> | ReactElement<unknown, string | JSXElementConstructor<any>>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleCSSProperties | ((state: DialogBackdropState) => CSSProperties | undefined)—Style applied to the element, or a function that returns a style object based on the component's state.

Plus the DOM props of the element it renders. Source: alert-dialog/components/alert-dialog-overlay.tsx.

AlertDialog.Portal

PropTypeDefault
exitExit—Inside a <Presence>: plays this child's way out before it unmounts.
classNamestring | ((state: DialogPortalState) => string | undefined)—CSS class applied to the element, or a function that returns a class based on the component's state.
containerHTMLElement | RefObject<HTMLElement | ShadowRoot | null> | ShadowRoot | null—A parent element to render the portal element into.
keepMountedboolean—Whether to keep the portal mounted in the DOM while the popup is hidden.
renderComponentRenderFn<HTMLProps, DialogPortalState> | ReactElement<unknown, string | JSXElementConstructor<any>>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleCSSProperties | ((state: DialogPortalState) => CSSProperties | undefined)—Style applied to the element, or a function that returns a style object based on the component's state.

Plus the DOM props of the element it renders. Source: alert-dialog/components/alert-dialog-portal.tsx.

AlertDialog.Title

PropTypeDefault
exitExit—Inside a <Presence>: plays this child's way out before it unmounts.
classNamestring | ((state: DialogTitleState) => string | undefined)—CSS class applied to the element, or a function that returns a class based on the component's state.
renderComponentRenderFn<HTMLProps, DialogTitleState> | ReactElement<unknown, string | JSXElementConstructor<any>>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleCSSProperties | ((state: DialogTitleState) => CSSProperties | undefined)—Style applied to the element, or a function that returns a style object based on the component's state.

Plus the DOM props of the element it renders. Source: alert-dialog/components/alert-dialog-title.tsx.

AlertDialog.Trigger

PropTypeDefault
exitExit—Inside a <Presence>: plays this child's way out before it unmounts.
classNamestring | ((state: DialogTriggerState) => string | undefined)—CSS class applied to the element, or a function that returns a class based on the component's state.
handleAlertDialogHandle<unknown>—A handle to associate the trigger with an alert dialog. Can be created with the AlertDialog.createHandle() method.
idstring—ID of the trigger. In addition to being forwarded to the rendered element, it is also used to specify the active trigger for the dialog in controlled mode (with the DialogRoot triggerId prop).
nativeButtonboolean—Whether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
payloadunknown—A payload to pass to the dialog when it is opened.
renderComponentRenderFn<HTMLProps, DialogTriggerState> | ReactElement<unknown, string | JSXElementConstructor<any>>—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleCSSProperties | ((state: DialogTriggerState) => CSSProperties | undefined)—Style applied to the element, or a function that returns a style object based on the component's state.

Plus the DOM props of the element it renders. Source: alert-dialog/components/alert-dialog-trigger.tsx.

ConfirmDialog · Dialog · ResponsiveDialog