Skip to main content

@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).

ParamType
optionsAlertOptions

Returns: Promise<void>

prompt(options)​

Shows an input dialog; when canceled, value is an empty string and cancelled is true.

ParamType
optionsPromptOptions

Returns: Promise<PromptResult>

confirm(options)​

Shows a confirmation dialog.

ParamType
optionsConfirmOptions

Returns: Promise<ConfirmResult>

Interfaces​

AlertOptions​

PropTypeDescription
titlestringDialog title.
messagestringDialog message.
buttonTitlestringButton label (default 'OK').

PromptOptions​

PropTypeDescription
titlestringDialog title.
messagestringDialog message.
okButtonTitlestringOK button label (default 'OK').
cancelButtonTitlestringCancel button label (default 'Cancel').
inputPlaceholderstringInput placeholder (maps to DisplayPromptAsync's placeholder). MAUI has no maxLength / keyboard customization parameters, so they are not exposed.
inputTextstringPre-filled input text.

PromptResult​

PropTypeDescription
valuestringEntered text (empty string when canceled).
cancelledbooleanWhether the dialog was canceled.

ConfirmOptions​

PropTypeDescription
titlestringDialog title.
messagestringDialog message.
okButtonTitlestringOK button label (default 'OK').
cancelButtonTitlestringCancel button label (default 'Cancel').

ConfirmResult​

PropTypeDescription
valuebooleantrue when the OK button is clicked.