Actions

Alert Dialog

A modal confirmation before an important or destructive action, with Cancel as the safe default.

Class nameTypeDescription
alert-dialogplf:alert-dialogComponentOn a Modal dialog, beside modal
alert-dialog-headerplf:alert-dialog-headerPartGroups the icon, title and description
alert-dialog-iconplf:alert-dialog-iconPartAn optional icon box above the title, where a color draws its icon
alert-dialog-svgplf:alert-dialog-svgPartYour own SVG in the box, in place of the color's icon; an icon class there doesn't need it
alert-dialog-titleplf:alert-dialog-titlePartThe dialog's heading
alert-dialog-descriptionplf:alert-dialog-descriptionPartMuted text under the title
alert-dialog-footerplf:alert-dialog-footerPartCancel and confirm; stacked on small screens
alert-dialog-successplf:alert-dialog-successColorA green icon
alert-dialog-errorplf:alert-dialog-errorColorA red icon, for a destructive action
alert-dialog-warningplf:alert-dialog-warningColorA yellow icon
alert-dialog-infoplf:alert-dialog-infoColorA blue icon

Default

Point aria-describedby at the description; the heading names the dialog and focus starts on Cancel. When the confirm button closes it, plf:modal:close reports detail.action as confirm.

Publish this draft?

Everyone with access will see it. You can keep editing afterwards.

Delete this project?

This permanently deletes the project and its files. It cannot be undone.

Save these changes?

Your changes are being saved.

JavaScript

Alert Dialog needs JavaScript. The Full script (pelatform-ui.min.js) starts every component on page load, with no code of your own; with ESM imports, call init() yourself, as in Installation. For markup you add later, see Dynamic content.

<link rel="stylesheet" href="pelatform-ui.min.css">
<link rel="stylesheet" href="icons/icons.min.css">
<script src="pelatform-ui.min.js" defer></script>
<link rel="stylesheet" href="pelatform-ui.prefixed.min.css">
<link rel="stylesheet" href="icons/icons.prefixed.min.css">
<script src="pelatform-ui.min.js" defer></script>
Attribute Purpose
aria-describedby Required; non-empty text inside the dialog
data-plf-alert-dialog-action="cancel" The one Cancel button
data-plf-alert-dialog-action="confirm" The one confirm button; while your action runs, give it disabled and aria-busy="true"

A Modal that holds these two actions is an alert dialog, which a click outside never closes. Both actions are <button> elements with data-plf-trigger="modal:close".

Methods and events

Alert Dialog uses the Modal methods, events and keyboard. Its plf:modal:before-close and plf:modal:close events add detail.action: confirm when the confirm button closes it, cancel for Cancel, Escape and close(). Avoid <form method="dialog">, which skips plf:modal:before-close.

From a script, PLF.Dialog.fire() confirms and then shows the result with SweetAlert’s options, on dialogs it creates: see Dialogs from JavaScript.

React

AlertDialog from @pelatform/react renders this dialog on a Modal, which a click outside never closes: the application opens it with open and closes it in onOpenChange, and focus starts on AlertDialogCancel.

Prop Values Default
open true while the dialog is open Required
onOpenChange (open, reason), called when the dialog asks to close: cancel (Cancel), confirm (the action) or keyboard (Escape); keep open to stay open None
color success, error, warning, info None

The parts:

Part Element
AlertDialogHeader A div with alert-dialog-header
AlertDialogIcon A span with alert-dialog-icon: empty, the color’s icon; an Icon inside takes its place
AlertDialogTitle An h2 with alert-dialog-title, or another heading with level, which names the dialog
AlertDialogDescription A p with alert-dialog-description, which describes the dialog
AlertDialogFooter A div with alert-dialog-footer
AlertDialogCancel A button with btn btn-outline, which takes the first focus and closes with cancel
AlertDialogAction A Button, primary unless given another color, which closes with confirm unless its onClick calls preventDefault(): for a busy state, set its loading and close the dialog when the action ends

Other props are the element’s own, className and ref included. To confirm from your code without this markup, use useDialog().

CSS variables

The surface, padding, radius and backdrop come from the Modal variables.

Variable Default
--plf-alert-dialog-width 28rem, capped to the viewport
--plf-alert-dialog-icon-bg --plf-color-surface-muted
--plf-alert-dialog-icon-color --plf-color-text
--plf-alert-dialog-icon-size 1.25em

Built with Pelatform UIv0.1.0

Components

Getting started

Foundations

Components

Actions

Data display

Navigation

Feedback

Data input

Layout

Advanced

Integrations

Blocks

Application

Authentication

Icons