GitHubopen_in_new

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

The tables below are generated from source types and stay in sync with API changes.

ShowDialogOptions

FieldTypeRequiredDescriptionDefault
headlinestringNoOptional dialog headline text.-
contentstringNoOptional supporting text content.-
iconstringNoOptional Material Symbols icon name rendered above the headline.-
actionsDialogAction[]NoAction buttons rendered in the dialog footer.-
closeOnBackdropboolean | undefinedNoWhether clicking the backdrop closes the dialog.true
role'dialog' | 'alertdialog'NoARIA role forwarded to the root dialog element.-

DialogAction

FieldTypeRequiredDescriptionDefault
labelstringYesLabel shown in the action row.-
valuestring | undefinedNoValue returned when this action closes the dialog.-
colorButtonProps['color']NoVisual style forwarded to the Button component.-
disabledboolean | undefinedNoWhether the action button is disabled.-
autofocusboolean | undefinedNoWhether this action should autofocus when rendered.-
closeOnClickboolean | undefinedNoWhether clicking the action should close the dialog.-
onClick(() => void | boolean | Promise<void | boolean>) | undefinedNoOptional callback invoked before the dialog closes. Return `false` to keep it 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.