Alert Dialog
<button class="btn btn-destructive" data-pk-dialog-open="delete-project">Delete project</button>
<dialog class="alert-dialog" id="delete-project"> <div class="alert-dialog-header"> <h3 class="alert-dialog-title">Delete this project?</h3> <p class="alert-dialog-description"> Every deployment, environment and log will be removed. This cannot be undone. </p> </div> <div class="alert-dialog-footer"> <button class="btn btn-outline" data-pk-dialog-close>Cancel</button> <button class="btn btn-destructive" data-pk-dialog-close="confirm">Delete</button> </div></dialog><button class="btn btn-destructive" data-pk-dialog-open="confirm-delete">Delete</button>
<dialog class="alert-dialog" id="confirm-delete"> <div class="alert-dialog-header"> <h3 class="alert-dialog-title">Delete this project?</h3> <p class="alert-dialog-description">This cannot be undone.</p> </div> <div class="alert-dialog-footer"> <button class="btn btn-outline" data-pk-dialog-close>Cancel</button> <button class="btn btn-destructive" data-pk-dialog-close="confirm">Delete</button> </div></dialog>Composition
Section titled “Composition”<button class="btn btn-outline" data-pk-dialog-open="ad-composition">Open</button>
<dialog class="alert-dialog" id="ad-composition"> <div class="alert-dialog-header"> <div class="alert-dialog-media"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <circle cx="12" cy="12" r="10"></circle> <path d="M12 8v4M12 16h.01"></path> </svg> </div> <h3 class="alert-dialog-title">Title</h3> <p class="alert-dialog-description">The consequence, spelled out.</p> </div> <div class="alert-dialog-footer"> <button class="btn btn-outline" data-pk-dialog-close>Cancel</button> <button class="btn" data-pk-dialog-close="confirm">Confirm</button> </div></dialog>| Class | Part |
|---|---|
.alert-dialog | The <dialog> element itself |
.alert-dialog-header | Title area, centred on small screens |
.alert-dialog-media | Optional icon that pairs with the title |
.alert-dialog-title | Heading — becomes the accessible name |
.alert-dialog-description | The consequence, spelled out |
.alert-dialog-footer | Cancel and confirm |
Attributes
Section titled “Attributes”| Attribute | On | Meaning |
|---|---|---|
data-pk-dialog-open="<id>" | any control | Opens it |
data-pk-dialog-close[="<value>"] | a control inside | Closes it, optionally setting returnValue |
data-size="sm" | the alert dialog | Compact: stays narrow and splits the footer into two columns |
data-state="open" | "closed" | the alert dialog | Set by the runtime |
The events are the dialog’s: pk:dialog:before-open, pk:dialog:open and pk:dialog:close.
<button class="btn btn-outline" data-pk-dialog-open="ad-basic">Leave page</button>
<dialog class="alert-dialog" id="ad-basic"> <div class="alert-dialog-header"> <h3 class="alert-dialog-title">Leave without saving?</h3> <p class="alert-dialog-description">Your changes will be lost.</p> </div> <div class="alert-dialog-footer"> <button class="btn btn-outline" data-pk-dialog-close>Stay</button> <button class="btn" data-pk-dialog-close="confirm">Leave</button> </div></dialog>data-size="sm" keeps the panel narrow at every width and gives the two actions equal halves,
which suits a short yes-or-no.
<button class="btn btn-outline" data-pk-dialog-open="discard-draft">Discard draft</button>
<dialog class="alert-dialog" id="discard-draft" data-size="sm"> <div class="alert-dialog-header"> <h3 class="alert-dialog-title">Discard draft?</h3> <p class="alert-dialog-description">Your unsaved changes will be lost.</p> </div> <div class="alert-dialog-footer"> <button class="btn btn-outline" data-pk-dialog-close>Keep</button> <button class="btn btn-destructive" data-pk-dialog-close="confirm">Discard</button> </div></dialog>.alert-dialog-media sits above the title on a small screen and moves beside it once there is
room.
<button class="btn btn-outline" data-pk-dialog-open="revoke-access">Revoke access</button>
<dialog class="alert-dialog" id="revoke-access"> <div class="alert-dialog-header"> <div class="alert-dialog-media"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <path d="M12 9v4m0 4h.01M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z"></path> </svg> </div> <h3 class="alert-dialog-title">Revoke access?</h3> <p class="alert-dialog-description"> This member loses access immediately and any tokens they created stop working. </p> </div> <div class="alert-dialog-footer"> <button class="btn btn-outline" data-pk-dialog-close>Cancel</button> <button class="btn" data-pk-dialog-close="confirm">Revoke</button> </div></dialog>Small with Media
Section titled “Small with Media”<button class="btn btn-outline" data-pk-dialog-open="ad-small-media">Open</button>
<dialog class="alert-dialog" id="ad-small-media" data-size="sm"> <div class="alert-dialog-header"> <div class="alert-dialog-media"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <path d="M3 6h18M8 6V4h8v2M19 6l-1 14H6L5 6"></path> </svg> </div> <h3 class="alert-dialog-title">Delete file?</h3> <p class="alert-dialog-description">It will not go to the bin.</p> </div> <div class="alert-dialog-footer"> <button class="btn btn-outline" data-pk-dialog-close>Cancel</button> <button class="btn btn-destructive" data-pk-dialog-close="confirm">Delete</button> </div></dialog>Destructive
Section titled “Destructive”The confirm button carries the destructive variant, and the description says exactly what is lost.
<button class="btn btn-destructive" data-pk-dialog-open="ad-destructive">Delete account</button>
<dialog class="alert-dialog" id="ad-destructive"> <div class="alert-dialog-header"> <div class="alert-dialog-media"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <path d="M12 9v4m0 4h.01M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z"></path> </svg> </div> <h3 class="alert-dialog-title">Delete your account?</h3> <p class="alert-dialog-description"> Every project, deployment and invoice goes with it. This cannot be undone. </p> </div> <div class="alert-dialog-footer"> <button class="btn btn-outline" data-pk-dialog-close>Keep my account</button> <button class="btn btn-destructive" data-pk-dialog-close="confirm">Delete everything</button> </div></dialog>Set dir="rtl" on the page or on any subtree — padding, corners and positions follow the reading
direction on their own. See the button page for a live example.
Writing the question
Section titled “Writing the question”The title asks, the description says what happens, and the confirm button names the action rather than agreeing:
<h3 class="alert-dialog-title">Delete this project?</h3><p class="alert-dialog-description">Every deployment and log will be removed.</p>...<button class="btn btn-destructive" data-pk-dialog-close="confirm">Delete</button>Cancel comes first in the markup so it is the first thing keyboard and screen reader users reach, and it renders last on wider screens.
Handling the answer
Section titled “Handling the answer”document.getElementById("delete-project").addEventListener("pk:dialog:close", (event) => { if (event.detail.returnValue === "confirm") deleteProject();});Esc closes it, the same as any dialog, and counts as cancelling — returnValue is empty. Treat
anything other than your confirm value as “no”.