showDialog

showDialog() is the programmatic entry point for modal dialogs. It mounts a temporary Dialog instance, waits for it to close, and resolves with the dialog result.

Basic Usage

ts
import { showDialog } from '@rikkaw/m3-vue';

const result = await showDialog({
  headline: 'Delete file?',
  content: 'This action cannot be undone.',
  actions: [
    { label: 'Cancel', value: 'cancel' },
    { label: 'Delete', value: 'confirm' },
  ],
});

The promise resolves to the clicked action value. If no explicit value is provided, the action label is used instead.

Options

FieldTypeDefaultNotes
headlinestring-Optional dialog title
contentstring-Optional supporting text
iconstring-Material Symbols icon name rendered in the icon slot
actionsDialogAction[][{ label: 'OK', value: 'confirm', color: 'text' }]Footer actions
closeOnBackdropbooleantrueCloses when the backdrop is clicked
role'dialog' | 'alertdialog'-Forwarded to the rendered <dialog> element

DialogAction fields:

FieldTypeDefaultNotes
labelstring-Visible button text
valuestringlabelValue used to resolve the promise
colorButtonProps['color']'text'Button style
disabledbooleanfalseDisables the action
autofocusbooleanfalseAutofocuses the action button
closeOnClickbooleantrueKeep the dialog open by setting this to false
onClick() => void | boolean | Promise<void | boolean>-Return false to keep the dialog open

Behavior Notes

  • Calling showDialog() outside a browser environment rejects the promise.
  • If an action callback throws or rejects, the promise rejects with that error.
  • Cleanup waits for the dialog exit animation before unmounting the temporary app host.

For manually rendered dialogs and slot-based composition, see Dialog.