Alert Dialog

Save notes locally or confirm discarding them in an alert dialog. The least destructive action receives initial focus.

Corresponding W3C APG example

Example

Discard notes?

This removes your notes from this browser.

Keyboard interaction

Control/Command+S saves while editing. Tab stays in the confirmation dialog; Escape or No cancels; Yes discards.

Events

Listen on the widget or delegate to <axxy-scope> or document. All custom events bubble.

  • axxy-dialog-open — Bubbling event dispatched when a modal dialog opens. (target: <dialog>, detail: { dialog: HTMLDialogElement, invoker: HTMLElement|null })
  • axxy-dialog-close — Bubbling event dispatched when a modal dialog closes. (target: <dialog>, detail: { dialog: HTMLDialogElement, invoker: HTMLElement|null })
  • close — Standard non-bubbling dialog close event. (target: <dialog>, detail: Native Event)

Events reference and examples

Example HTML

<axxy-scope>
  <label for="demo-notes">Notes</label>
  <textarea id="demo-notes">Example notes</textarea>
  <div>
    <button type="button" id="demo-save">Save</button>
    <button type="button" aria-controls="demo-confirm" id="demo-discard">Discard</button>
  </div>
  <p role="alert" id="demo-alert"></p>
  <dialog role="alertdialog" id="demo-confirm" aria-labelledby="demo-confirm-title" aria-describedby="demo-confirm-description">
    <h2 id="demo-confirm-title">Discard notes?</h2>
    <p id="demo-confirm-description">This removes your notes from this browser.</p>
    <button type="button" autofocus>No</button>
    <button type="button" id="demo-yes">Yes</button>
  </dialog>
</axxy-scope>