dialogs — dialogs
The dialogs module shows modal-style UI for prompts, confirmations, text input, and list selection. Use it for lightweight user interaction.
It supports in-app dialogs and overlay-style windows, with layout and behavior controlled through DialogProperties.
Import the module:
const dialogs = require("dialogs");
// e.g. dialogs.showInputDialog("Title", "Default text");Or import individual functions:
const { showInputDialog } = require("dialogs");
showInputDialog("Title", "Default text");Table of contents
Interfaces
Types
Constants
Functions
- buildDialog
- setDefaultDialogType
- showAlertDialog
- showConfirmDialog
- showDialog
- showInputDialog
- showMultiChoiceDialog
- showSelectDialog
- showSingleChoiceDialog
Types
Dialog
Dialog: android.app.Dialog & DialogExt
A dialog handle: Android’s Dialog plus the extra helpers on DialogExt.
DialogType
DialogType: "overlay" | "app"
How the dialog is presented:
overlay: Can appear above other apps; requires overlay (floating window) permission.app: In-app dialog bound to the currentActivity; no extra overlay permission.
Constants
defaultDialogType
defaultDialogType:DialogType='app'
Default presentation mode. Change it with setDefaultDialogType.
See also
Functions
buildDialog
buildDialog(properties: DialogProperties): Promise<Dialog>
Builds a dialog without showing it yet. Configure title, message, progress, inputs, buttons, and more via properties.
Parameters
| Name | Type | Description |
|---|---|---|
properties | DialogProperties | Full dialog configuration. |
Returns
Promise<Dialog>
Resolves to a Dialog instance; call its show() / lifecycle methods as needed.
setDefaultDialogType
setDefaultDialogType(type: DialogType): void
See also: defaultDialogType
Parameters
| Name | Type | Description |
|---|---|---|
type | DialogType | New default for subsequent dialogs. |
Returns
void
showAlertDialog
showAlertDialog(title: string, properties?: DialogProperties): Promise<void>
Shows an informational dialog: title, body text, and a single confirm action.
Example
"nodejs";
const { showAlertDialog } = require("dialogs");
async function alert() {
await showAlertDialog("This is an alert dialog.");
await showAlertDialog("Summary", { content: "Some description" });
}
alert();Parameters
| Name | Type | Description |
|---|---|---|
title | string | Dialog title. |
properties? | DialogProperties | Optional layout and copy (e.g. content). |
Returns
Promise<void>
Resolves when the dialog is dismissed.
showConfirmDialog
showConfirmDialog(title: string, properties?: DialogProperties): Promise<boolean>
Shows OK / Cancel (or custom positive / negative labels). Resolves to whether the user confirmed.
Example
"nodejs";
const dialogs = require("dialogs");
async function confirm() {
const sure = await dialogs.showConfirmDialog("Are you sure?");
console.log(sure); // true or false
console.log(
await dialogs.showConfirmDialog("Are you sure?", {
positive: "Yes",
negative: "No",
}),
);
}
confirm();Parameters
| Name | Type | Description |
|---|---|---|
title | string | Dialog title. |
properties? | DialogProperties | Extra options (button labels, content, etc.). |
Returns
Promise<boolean>
true if the user tapped the positive action, false otherwise.
showDialog
showDialog(properties: DialogProperties): Promise<Dialog>
Like buildDialog, but builds and shows the dialog immediately (no separate show()).
Parameters
| Name | Type | Description |
|---|---|---|
properties | DialogProperties | Full dialog configuration. |
Returns
Promise<Dialog>
Resolves to the shown dialog instance.
showInputDialog
showInputDialog(title: string, prefill?: string, properties?: DialogProperties): Promise<string | null>
Shows a single-line (or configured) text input dialog.
Example
"nodejs";
const dialogs = require("dialogs");
async function inputDialog() {
const name = await dialogs.showInputDialog("Input your name", "Tony");
if (name != null && name !== "") {
console.log(`hello, ${name}`);
}
}
inputDialog();Parameters
| Name | Type | Description |
|---|---|---|
title | string | Dialog title. |
prefill? | string | Initial text in the field. |
properties? | DialogProperties | Optional styling and behavior. |
Returns
Promise<string | null>
The entered string, or null if the user cancelled.
showMultiChoiceDialog
showMultiChoiceDialog(title: string, items: string[], initialSelectedIndices?: number[], properties?: DialogProperties): Promise<number[] | null>
Multi-select list with title and checkable items. After the user confirms, resolves to the indices of checked rows (0-based).
Parameters
| Name | Type | Description |
|---|---|---|
title | string | Dialog title. |
items | string[] | Option labels. |
initialSelectedIndices? | number[] | Pre-selected indices, e.g. [0, 2] for first and third. |
properties? | DialogProperties | Optional configuration. |
Returns
Promise<number[] | null>
Selected row indices (0-based). If the user cancels, the documented behavior is an empty array []; typings may still include null, so treat “no selection” as !result || result.length === 0 when in doubt.
showSelectDialog
showSelectDialog(title: string, items: string[], properties?: DialogProperties): Promise<number>
Simple list: user taps one row (no separate OK step in the default flow). Returns the tapped item’s index.
Example
"nodejs";
const { showSelectDialog } = require("dialogs");
async function select() {
const i = await showSelectDialog("Select an item", [
"item1",
"item2",
"item3",
]);
console.log(`selected item: ${i}`);
}
select();Parameters
| Name | Type | Description |
|---|---|---|
title | string | Dialog title. |
items | string[] | Option labels. |
properties? | DialogProperties | Optional configuration. |
Returns
Promise<number>
Selected index, or -1 if the user cancelled.
showSingleChoiceDialog
showSingleChoiceDialog(title: string, items: string[], initialSelectedIndex?: number, properties?: DialogProperties): Promise<number>
Radio-style single choice: user picks one option and confirms.
Example
"nodejs";
const { showSingleChoiceDialog } = require("dialogs");
async function singleChoice() {
const i = await showSingleChoiceDialog("Choose an item", [
"item1",
"item2",
"item3",
]);
console.log(`selected item: ${i}`);
}
singleChoice();Parameters
| Name | Type | Description |
|---|---|---|
title | string | Dialog title. |
items | string[] | Option labels. |
initialSelectedIndex? | number | Default selected index into items. |
properties? | DialogProperties | Optional configuration. |
Returns
Promise<number>
Selected index, or -1 if the user cancelled.
