@napacitor/dialog
Native dialog plugin (corresponds to @capacitor/dialog).
Installation
To use npm:
npm install @napacitor/dialog
To use yarn:
yarn add @napacitor/dialog
Sync native files:
npx nap sync
Usage
import { Dialog } from '@napacitor/dialog';
await Dialog.alert({ title: 'Notice', message: 'Hello Napacitor', buttonTitle: 'Got it' });
const { value } = await Dialog.confirm({ title: 'Confirm', message: 'Continue?' });
console.log(value); // true / false
const { value: text, cancelled } = await Dialog.prompt({
title: 'Input',
message: 'Your name?',
okButtonTitle: 'OK',
cancelButtonTitle: 'Cancel',
});
How It Works
Wraps the APIs described in the .NET MAUI Page.DisplayAlert / DisplayPromptAsync documentation (alert / confirm use DisplayAlert, prompt uses DisplayPromptAsync; on Windows, MAUI falls back to ContentDialog). Dialogs must be shown on the UI thread; the plugin switches via MainThread.InvokeOnMainThreadAsync internally and throws UNAVAILABLE when the host window has not been created / there is no page. This plugin is one of the few that requires a reference to the Microsoft.Maui.Controls package (the Page API belongs to the Controls layer).
Permissions
Android
No additional configuration required.
iOS
No additional configuration required.
Windows
No additional configuration required.
API
alert(options)
Shows an alert dialog (single button).
| Param | Type |
|---|---|
options | AlertOptions |
Returns: Promise<void>
prompt(options)
Shows an input dialog; when canceled, value is an empty string and cancelled is true.
| Param | Type |
|---|---|
options | PromptOptions |
Returns: Promise<PromptResult>
confirm(options)
Shows a confirmation dialog.
| Param | Type |
|---|---|
options | ConfirmOptions |
Returns: Promise<ConfirmResult>
Interfaces
AlertOptions
| Prop | Type | Description |
|---|---|---|
title | string | Dialog title. |
message | string | Dialog message. |
buttonTitle | string | Button label (default 'OK'). |
PromptOptions
| Prop | Type | Description |
|---|---|---|
title | string | Dialog title. |
message | string | Dialog message. |
okButtonTitle | string | OK button label (default 'OK'). |
cancelButtonTitle | string | Cancel button label (default 'Cancel'). |
inputPlaceholder | string | Input placeholder (maps to DisplayPromptAsync's placeholder). MAUI has no maxLength / keyboard customization parameters, so they are not exposed. |
inputText | string | Pre-filled input text. |
PromptResult
| Prop | Type | Description |
|---|---|---|
value | string | Entered text (empty string when canceled). |
cancelled | boolean | Whether the dialog was canceled. |
ConfirmOptions
| Prop | Type | Description |
|---|---|---|
title | string | Dialog title. |
message | string | Dialog message. |
okButtonTitle | string | OK button label (default 'OK'). |
cancelButtonTitle | string | Cancel button label (default 'Cancel'). |
ConfirmResult
| Prop | Type | Description |
|---|---|---|
value | boolean | true when the OK button is clicked. |