Skip to content

AlertDialog

A dialog that forces a decision before moving on. It blocks, and unlike the Modal, clicking the backdrop does NOT dismiss it. For destructive or irreversible confirmations—deleting, canceling, discarding changes.

Overlays · TaishoDS Core, in plain HTML.

Examples

One working example per case. Each example is the HTML of its preview—copy it as is, and with Core’s CSS and JS loaded, it looks and works the same.

Confirm account deletion

html

Confirm by typing the project name

html

A more descriptive name

html

Class reference

Every value of each modifier, with its HTML ready to copy.

Variant

The kind of action: default, or danger for a destructive one (the confirm button turns danger).

html

Confirm text

Confirm stays disabled until the exact text is typed (for dangerous deletions).

html

When to use

  • The action is destructive or irreversible and deserves an explicit confirmation.
  • Closing it by accident would have consequences, so it needs a deliberate answer.
  • The choice comes down to two or three clear paths (confirm / cancel).

When not to use

  • It’s information or a task that can be closed at no cost → modal.
  • The notice doesn’t block anything and can live on the page → banner or note.
  • It’s a notification about something that already happened → toast.

Do

  • Name the action on the button: “Delete project,” not “OK.”
  • Mark the dangerous action visually (variant-danger on the confirm button) and leave cancel as the safe way out.
  • If the deletion can’t be undone (a whole project, an account), use data-ts-confirm-text to ask the user to type the name to confirm. Confirm stays disabled until it matches.

Don’t

  • Don’t use it for neutral notices. If nothing is lost, don’t block the user.
  • Don’t offer five options—if there are more than a couple of paths, it isn’t a confirmation.

TaishoDS Core

Needs Core’s JS, which hooks in through data-ts-* attributes.

It’s a modal <dialog>. The browser handles opening, closing, focus trapping, and Esc, and the destructive variant is styling only. The only thing that needs JavaScript is typed confirmation—typing an exact text to enable Confirm.

Core hooks into it through these attributes. They go in the markup, and there’s nothing to initialize.

  • data-ts-confirm
  • data-ts-confirm-input
  • data-ts-confirm-text
  • data-ts-field-spinner
  • data-ts-input

What it does: Only if you ask for typed confirmation. The <dialog> takes data-ts-confirm-text="...", the field takes data-ts-confirm-input, and the button takes data-ts-confirm (rendered disabled). Core enables the button when the typed text matches exactly, disables it again while loading, and clears the field when the dialog closes. Without typed confirmation there’s nothing to initialize. Initial focus lands on the field, the dialog’s first control.

Limitation

The trigger uses invoker commands (`command` and `commandfor`), which browsers ship from Chrome 135, Firefox 144, and Safari 26.2. In older ones, Core’s JS runs the commands on the dialog. If you didn’t load that JS, the button doesn’t open it and you need to call `dialog.showModal()` from your own code.

From the CDN, without a build, this component has no file of its own—it comes with taisho.base.css and the files below. Also load:

  • taisho.button.css
  • taisho.icon.css
  • taisho.input.css
  • taisho.kbd.css
  • taisho.modal.css
  • taisho.spinner.css

For how Core works in general, see Behavior.

Accessibility

Implements the Alert Dialog pattern from the WAI-ARIA APG.

  • alertdialog role. The screen reader announces the title and description on open.
  • The accessible name comes from the title (aria-labelledby). An aria-label or aria-labelledby on the <dialog> replaces it. With no name at all (a title attribute also counts as a name), Core warns in the console when the page is served from localhost.
  • Initial focus lands on the dialog’s first control. In the example that’s Cancel, which comes before the destructive action, so an accidental Enter doesn’t trigger it. If the order changes, put autofocus on Cancel.
  • With data-ts-confirm-text, in the example initial focus lands on the field, which is the first control (Confirm is still disabled, so there’s no risky Enter). The field has a visible <label>, and Confirm keeps the native disabled until the typed text matches exactly. On close, the field is cleared.
  • Esc is the same as canceling. Clicking the backdrop doesn’t close it—the decision must be explicit.
  • Inherits from <dialog>+showModal(): top layer, trapped focus, an inert background, and focus returned to the trigger on close. In WebKit, when the dialog was opened with the mouse, focus does not return to the trigger on close, because Safari does not focus a button on click.
  • While the dialog is open, the page behind it doesn’t scroll and keeps the scrollbar’s space (scrollbar-gutter: stable), so the content doesn’t shift.

Keyboard

On top of what the browser already does (Tab moves focus, Enter activates a button).

Key What it does
EscCancels—it never confirms. The destructive action requires intent.
EnterActivates the focused button.

Verification

What was actually tested. Anything that wasn’t tested says so—we’d rather say “not verified” than claim too much.

  • axe WCAG 2.2 A + AA in a real browser, in light and dark mode, before every release.
  • keyboard Key map documented above, checked against the component.
  • screen reader Not verified with a screen reader. Test it in your own combination of components, not just here, where each one appears alone and on its happy path.