Components

Dialog

A modal dialog that appears over the page and traps focus.

A modal panel that overlays the page. Focus is trapped inside while open and restored to the trigger when closed. Screen readers are informed via role="dialog" and aria-modal.

For confirmations requiring a required response, use Alert Dialog instead.

Anatomy

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

Usage

Examples

Custom header with close button

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

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

    <template #body>
      <p>Dialog content here.</p>
    </template>
  </Dialog>
</template>

Fullscreen dialog

<template>
  <Dialog :fullscreen="true" title="Full view">
    <template #trigger="{ toggle }">
      <button @click="() => toggle()">Expand</button>
    </template>
    <template #body>
      <p>Takes up the entire viewport.</p>
    </template>
  </Dialog>
</template>

Prevent close on backdrop click

<template>
  <Dialog :close-on-backdrop-click="false" title="Required step">
    <template #trigger="{ toggle }">
      <button @click="() => toggle()">Start</button>
    </template>
    <template #footer="{ close }">
      <button @click="() => close()">Complete</button>
    </template>
  </Dialog>
</template>

Programmatic control

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

const dialog = ref();
</script>

<template>
  <Dialog ref="dialog" title="Notification">
    <template #body><p>You have a new message.</p></template>
    <template #footer="{ close }">
      <button @click="() => close()">Dismiss</button>
    </template>
  </Dialog>

  <button @click="dialog?.open()">Show notification</button>
</template>

API Reference

Props

PropTypeDefaultDescription
titlestringConvenience title. Slot #title takes priority.
descriptionstringConvenience description. Slot #description takes priority.
closeOnBackdropClickbooleantrueClose when clicking the overlay.
fullscreenbooleanfalseExpand the dialog to fill the viewport.
teleportstring | false"body"Teleport target.
transitionstring | false"akaza-dialog"Named Vue transition.
durationnumber100Transition duration in ms.
asstring"div"Root element tag.
uiDialogUiCSS class overrides.

Slots

SlotScoped propsDescription
trigger{ isOpen, open, close, toggle }Element that opens the dialog.
overlayBackdrop element.
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.

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.

Emits

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

UI Options

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