Skip to main content
Version: v6

@capacitor/dialog

The Dialog API provides methods for triggering native dialog windows for alerts, confirmations, and input prompts

Installโ€‹

npm install @capacitor/dialog
npx cap sync

Exampleโ€‹

import { Dialog } from '@capacitor/dialog';

const showAlert = async () => {
await Dialog.alert({
title: 'Stop',
message: 'this is an error',
});
};

const showConfirm = async () => {
const { value } = await Dialog.confirm({
title: 'Confirm',
message: `Are you sure you'd like to press the red button?`,
});

console.log('Confirmed:', value);
};

const showPrompt = async () => {
const { value, cancelled } = await Dialog.prompt({
title: 'Hello',
message: `What's your name?`,
});

console.log('Name:', value);
console.log('Cancelled:', cancelled);
};

APIโ€‹

alert(...)โ€‹

alert(options: AlertOptions) => Promise<void>

Show an alert dialog

ParamType
options
AlertOptions

Since: 1.0.0


prompt(...)โ€‹

prompt(options: PromptOptions) => Promise<PromptResult>

Show a prompt dialog

ParamType
options
PromptOptions

Returns:

Promise<PromptResult>

Since: 1.0.0


confirm(...)โ€‹

confirm(options: ConfirmOptions) => Promise<ConfirmResult>

Show a confirmation dialog

ParamType
options
ConfirmOptions

Returns:

Promise<ConfirmResult>

Since: 1.0.0


Interfacesโ€‹

AlertOptionsโ€‹

PropTypeDescriptionDefaultSince
titlestringTitle of the dialog.1.0.0
messagestringMessage to show on the dialog.1.0.0
buttonTitlestringText to use on the action button."OK"1.0.0

PromptResultโ€‹

PropTypeDescriptionSince
valuestringText entered on the prompt.1.0.0
cancelledbooleanWhether if the prompt was canceled or accepted.1.0.0

PromptOptionsโ€‹

PropTypeDescriptionDefaultSince
titlestringTitle of the dialog.1.0.0
messagestringMessage to show on the dialog.1.0.0
okButtonTitlestringText to use on the positive action button."OK"1.0.0
cancelButtonTitlestringText to use on the negative action button."Cancel"1.0.0
inputPlaceholderstringPlaceholder text for hints.1.0.0
inputTextstringPrepopulated text.1.0.0

ConfirmResultโ€‹

PropTypeDescriptionSince
valuebooleantrue if the positive button was clicked, false otherwise.1.0.0

ConfirmOptionsโ€‹

PropTypeDescriptionDefaultSince
titlestringTitle of the dialog.1.0.0
messagestringMessage to show on the dialog.1.0.0
okButtonTitlestringText to use on the positive action button."OK"1.0.0
cancelButtonTitlestringText to use on the negative action button."Cancel"1.0.0