# Alert dialog

A dialog that stops everything to ask for a yes or no before something is lost.

This is the HTML to build it with `dex.css`, for work outside the Dex codebase. Read https://brand.meetdex.ai/design.md first: it says how to set up a page and how to use the stylesheet. The page at https://brand.meetdex.ai/components/alert-dialog shows the Dex app's own React component, which only works inside the Dex codebase.

## HTML

A native `<dialog class="dex-dialog">`, opened with `showModal()`, which dims the page behind it. A title, one plain sentence, then the two buttons on the right, the safe one first:

```html
<dialog class="dex-dialog" id="discard" role="alertdialog" aria-labelledby="discard-title" aria-describedby="discard-text">
  <h2 class="dex-h3" id="discard-title">Discard your changes?</h2>
  <p class="dex-small dex-muted" id="discard-text" style="margin-top: 0.5rem">Your edits to this answer won't be saved.</p>
  <form method="dialog" style="display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.5rem">
    <button class="dex-button dex-button--outline" value="cancel" autofocus>Keep editing</button>
    <button class="dex-button" value="confirm">Discard changes</button>
  </form>
</dialog>

<script>
  const discard = document.getElementById('discard')
  // Open it with discard.showModal(). Both buttons close it; act on the answer here.
  discard.addEventListener('close', () => {
    if (discard.returnValue === 'confirm') {
      /* discard the edits */
    }
  })
</script>
```

- **Destructive**: when the action deletes or withdraws something, its button is `dex-button--destructive` ("Withdraw", "Delete role").
- **Without `<dialog>`** (a static mock or a screenshot): a `dex-dialog` inside a `dex-scrim`, as design.md shows.

## Rules

- Use an alert dialog only when something would be lost and the person has to answer before going on: discarding edits, withdrawing, deleting. For anything else, use a dialog (https://brand.meetdex.ai/components/dialog.md).
- No close button, and a press on the page behind it does nothing. The only ways out are its two buttons and Escape. A native `<dialog>` already ignores presses outside it.
- It opens with focus on the cancel button, the choice that loses nothing (`autofocus`), wherever that button sits.
- Both buttons close the dialog. Do the work when the confirm button closes it.
- Name each button for what it does: "Keep editing" and "Discard changes", never "No" and "Yes".
