Liking cljdoc? Tell your friends :D

x-cancel-dialogue

A confirmation modal dialog with headline, optional message, and confirm/cancel actions. Designed for destructive-action confirmation flows. Fires cancelable request events so host code can intercept before the dialog closes.


Tag

<x-cancel-dialogue></x-cancel-dialogue>

Attributes

AttributeTypeDefaultDescription
openbooleanfalseWhether the dialog is visible
disabledbooleanfalseDisables both action buttons
headlinestring"Discard changes?"Dialog title text
messagestringOptional body message below the headline
confirm-textstring"Discard"Label for the confirm button
cancel-textstring"Keep editing"Label for the cancel button
dangerbooleanfalseStyles the confirm button in the danger (red) variant

Properties

PropertyTypeReflects attribute
openbooleanopen
disabledbooleandisabled
headlinestringheadline
messagestringmessage
confirmTextstringconfirm-text
cancelTextstringcancel-text
dangerbooleandanger

Events

EventCancelableDetailDescription
x-cancel-dialogue-cancel-requestyes{ reason: string }Fired before cancel closes. preventDefault() keeps it open.
x-cancel-dialogue-cancelno{}Fired after dialog closes via cancel
x-cancel-dialogue-confirm-requestyes{}Fired before confirm closes. preventDefault() keeps it open.
x-cancel-dialogue-confirmno{}Fired after dialog closes via confirm

All events bubble and are composed.

cancel-request reason values

ReasonTrigger
"cancel-button"User clicked the cancel button
"backdrop"User clicked the backdrop
"escape"User pressed Escape

Accessibility

  • Renders a div with role="dialog" and aria-modal="true".
  • The dialog receives aria-labelledby pointing to the unique headline element.
  • Focus is trapped inside the dialog while open (Tab cycles between the two buttons).
  • Escape key fires cancel-request with reason: "escape".

Examples

Basic usage

<x-cancel-dialogue
  open
  headline="Discard changes?"
  message="Your unsaved changes will be lost."
></x-cancel-dialogue>

Danger variant with custom labels

<x-cancel-dialogue
  open
  headline="Delete item?"
  message="This action cannot be undone."
  confirm-text="Delete"
  cancel-text="Keep"
  danger
></x-cancel-dialogue>

Listening to events

const dialog = document.querySelector('x-cancel-dialogue');

// The dialog closes itself before firing confirm/cancel.
// No need to remove the open attribute manually.
dialog.addEventListener('x-cancel-dialogue-confirm', () => {
  performDelete();
});

Intercept confirm

dialog.addEventListener('x-cancel-dialogue-confirm-request', e => {
  if (!validationPassed) e.preventDefault();
});

ClojureScript (hiccup renderer)

[:x-cancel-dialogue
 {:open (when (:show-dialog state) "")
  :headline "Discard changes?"
  :message "Your unsaved changes will be lost."
  :on-x-cancel-dialogue-confirm
  (fn [_] (swap! app dissoc :show-dialog))
  :on-x-cancel-dialogue-cancel
  (fn [_] (swap! app dissoc :show-dialog))}]

[:x-button {:variant "danger"
            :on-click (fn [_] (swap! app assoc :show-dialog true))}
 "Delete item"]

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close