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
portalstringCSS selector of the element to portal the dialog into

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
"button"User clicked the cancel button
"backdrop"User clicked the backdrop
"escape"User pressed Escape

Accessibility

  • Renders a native <dialog> element opened with showModal().
  • The dialog receives aria-labelledby pointing to the headline element.
  • When message is present, aria-describedby points to the message element.
  • Focus is trapped inside the dialog while open.
  • 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');

dialog.addEventListener('x-cancel-dialogue-confirm', () => {
  dialog.removeAttribute('open');
  performDelete();
});

dialog.addEventListener('x-cancel-dialogue-cancel', () => {
  dialog.removeAttribute('open');
});

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