Components

Alert Dialog

A modal dialog that interrupts the user and requires a response.

An alert dialog interrupts the user with important content and blocks interaction with the rest of the page until dismissed. Focus is trapped inside and screen readers announce it as an alert.

Use this for destructive or irreversible actions. For non-critical dialogs, use Dialog instead.

Anatomy

  • #trigger — element that opens the dialog
  • #header — area containing the title and optional close control
  • #title — the dialog's accessible title
  • #description — supplementary description text
  • #body — main content area
  • #footer — action buttons (confirm / cancel)

Usage

Examples

Custom header

<template>
  <AlertDialog>
    <template #trigger="{ toggle }">
      <button @click="() => toggle()">Open</button>
    </template>

    <template #header="{ close, titleId }">
      <h2 :id="titleId">Are you sure?</h2>
      <button aria-label="Close" @click="() => close()"></button>
    </template>

    <template #body="{ descriptionId }">
      <p :id="descriptionId">This cannot be undone.</p>
    </template>

    <template #footer="{ close }">
      <button @click="() => close()">Cancel</button>
      <button @click="() => close()">Confirm</button>
    </template>
  </AlertDialog>
</template>

Programmatic control

Expose the component ref to open/close from outside.

<script setup lang="ts">
import { ref } from "vue";
import { AlertDialog } from "akaza-ui";

const dialog = ref();
</script>

<template>
  <AlertDialog ref="dialog">
    <template #footer="{ close }">
      <button @click="() => close()">Dismiss</button>
    </template>
  </AlertDialog>

  <button @click="dialog?.open()">Open from outside</button>
</template>

API Reference

Props

PropTypeDefaultDescription
titlestringConvenience title prop. Slot #title takes priority.
descriptionstringConvenience description prop. Slot #description takes priority.
teleportstring | false"body"Teleport target for the dialog.
transitionstring | false"akaza-alert-dialog"Named Vue transition to apply.
durationnumber150Transition duration in ms.
asstring"div"Root element tag.
uiAlertDialogUiCSS class overrides.

Slots

SlotScoped propsDescription
trigger{ isOpen, open, close, toggle }Element that opens the dialog.
header{ close, titleId }Header region.
titleDialog title. Defaults to the title prop.
descriptionDescription text. Defaults to the description prop.
body{ close, descriptionId }Main content area.
footer{ close }Action buttons region.

Emits

EventPayloadDescription
open-change[open: boolean, details]Fired when the open state changes.

Exposed methods

MethodSignatureDescription
open(reason?, event?) => voidOpens the dialog.
close(reason?, event?) => voidCloses the dialog.
toggle(reason?, event?) => voidToggles the dialog.
titleIdstringAuto-generated id for the title element.
descriptionIdstringAuto-generated id for the description element.

UI Options

KeyDescription
overlayThe backdrop overlay element.
contentThe dialog panel element.
headerThe header region.
titleThe title element.
descriptionThe description element.
bodyThe body region.
footerThe footer region.