Alert dialog

A modal confirmation for a consequential decision, with explicit Cancel and Confirm actions.

<tp-alert-dialog>
Alert dialog
Default density Compact density Restart from the initial state Show the copyable source
Delete project Cancel Delete project

Usage

Put the opening control in slot="trigger" and the two decisions in slot="cancel" and slot="confirm". label and description become the visible title and consequence text. Outside clicks never close an Alert Dialog; only Cancel, Confirm or Escape do.

It always traps focus and blocks background interaction: the whole document by default, or only one container with modality="container". Use Dialog for general workflows. Alert Dialog shares Dialog’s state, native surface, focus, triggers, handles, nesting and presence; only its decision policy and public part names differ.

Confirming

Cancel closes on its own. Confirm only supplies the button: clicking it does nothing until your handler performs the work and then closes the dialog with setOpen(false, 'close-action', event). State mode is fixed at first render. Use setOpen() for programmatic changes in uncontrolled mode. In controlled mode, accept tp-open-change by assigning dialog.open = event.detail.value.

Asynchronous confirm
Default density Compact density Restart from the initial state Show the copyable source
Revoke key Cancel Revoke key

For slow work, keep the dialog open, show progress on Confirm and lock Cancel until the request settles. If it fails, put the error in the dialog content instead of closing.

Content

Media and body
Default density Compact density Restart from the initial state Show the copyable source
Close editor

You have unsaved changes to Onboarding checklist. They will be lost if you leave now.

Keep editing Discard changes

The title, description and media slots take rich content when the attributes are not enough. Label both actions with their outcome, such as “Keep editing” and “Discard changes”, rather than “OK”. Alert Dialog has no generic corner Close: its named Cancel and Confirm actions communicate the decision.

Alert Dialog renders in a native dialog in the browser top layer, which escapes clipping and transformed ancestors while slotted content keeps inherited tokens. The inherited Dialog portal properties move it to another destination; with container modality it renders in place inside the container.

Focus

Initial focus on Confirm
Default density Compact density Restart from the initial state Show the copyable source
Publish Not yet Publish

Opening focuses Cancel by default, so a stray Enter never confirms a destructive action. initial-focus="confirm" suits safe, expected confirmations. Focus stays inside the dialog while it is open and returns to the trigger when it closes.

API Reference

Every element also accepts motion-policy.

Events

EventTypeDescriptiontp-open-changeTpSurfaceOpenChangeEventCancelable proposal to open or close, before the dialog changes; detail.value is the proposed state and detail.reason what asked (trigger-press, close-action, escape-key, outside-press, imperative-action and others). On a close, detail.preventUnmountOnClose() keeps the content mounted.tp-open-change-completeCustomEvent<{ open: boolean; }>After the dialog finishes opening or closing; detail.open.

Slots

SlotDescriptionmediaAn Icon or image above the title that marks the kind of decision.cancelThe action that declines; it closes the dialog when pressed.confirmThe action that carries out the decision; its handler does the work, then closes the dialog.actionsFurther footer actions beside Cancel and Confirm.defaultThe body of the task.triggerThe control that opens the dialog, usually a Button.titleThe title, in place of label.descriptionThe description, in place of description.footerFooter content with no close behavior, such as a secondary action.closeAn action that closes the dialog when pressed, after its own handlers.

Components, widgets and patterns that use this one.