Skip to content
Tauri
Releases

@tauri-apps/plugin-dialog

Interfaces

ConfirmDialogOptions

Properties

PropertyTypeDescription
cancelLabel?stringThe label of the cancel button.
okLabel?stringThe label of the confirm button.
title?stringThe title of the dialog. Defaults to the app name.
type?"info" | "warning" | "error"The type of the dialog. Defaults to info.

DialogFilter

Extension filters for the file dialog.

Since

2.0.0

Properties

PropertyTypeDescription
extensionsstring[]Extensions to filter, without a . prefix.

Example

typescript extensions: ['svg', 'png']
namestringFilter name.

FileResponse

Properties

PropertyType
base64Data?string
duration?number
height?number
mimeType?string
modifiedAt?number
name?string
pathstring
sizenumber
width?number

MessageDialogOptions

Since

2.0.0

Properties

PropertyTypeDescription
okLabel?stringThe label of the confirm button.
title?stringThe title of the dialog. Defaults to the app name.
type?"info" | "warning" | "error"The type of the dialog. Defaults to info.

OpenDialogOptions

Options for the open dialog.

Since

2.0.0

Properties

PropertyTypeDescription
defaultPath?stringInitial directory or file path.
directory?booleanWhether the dialog is a directory selection or not.
filters?DialogFilter[]The filters of the dialog.
multiple?booleanWhether the dialog allows multiple selection or not.
recursive?booleanIf directory is true, indicates that it will be read recursively later.
Defines whether subdirectories will be allowed on the scope or not.
title?stringThe title of the dialog window.

SaveDialogOptions

Options for the save dialog.

Since

2.0.0

Properties

PropertyTypeDescription
defaultPath?stringInitial directory or file path.
If it’s a directory path, the dialog interface will change to that folder.
If it’s not an existing directory, the file name will be set to the dialog’s file name input and the dialog will be set to the parent folder.
filters?DialogFilter[]The filters of the dialog.
title?stringThe title of the dialog window.

Type Aliases

OpenDialogReturn

OpenDialogReturn: <T> T["directory"] extends true ? T["multiple"] extends true ? string[] | null : string | null : T["multiple"] extends true ? FileResponse[] | null : FileResponse | null

Type parameters

Parameter
T extends OpenDialogOptions

Source: index.ts:101

Functions

ask()

ask(message, options?): Promise< boolean >

Shows a question dialog with Yes and No buttons.

Example

import { ask } from '@tauri-apps/plugin-dialog';
const yes = await ask('Are you sure?', 'Tauri');
const yes2 = await ask('This action cannot be reverted. Are you sure?', {
title: 'Tauri',
type: 'warning',
});

Since

2.0.0

Parameters

ParameterTypeDescription
messagestringThe message to show.
options?string | ConfirmDialogOptionsThe dialog’s options. If a string, it represents the dialog title.

Returns

Promise< boolean >

A promise resolving to a boolean indicating whether Yes was clicked or not.

Source: index.ts:249


confirm()

confirm(message, options?): Promise< boolean >

Shows a question dialog with Ok and Cancel buttons.

Example

import { confirm } from '@tauri-apps/plugin-dialog';
const confirmed = await confirm('Are you sure?', 'Tauri');
const confirmed2 = await confirm('This action cannot be reverted. Are you sure?', {
title: 'Tauri',
type: 'warning',
});

Since

2.0.0

Parameters

ParameterTypeDescription
messagestringThe message to show.
options?string | ConfirmDialogOptionsThe dialog’s options. If a string, it represents the dialog title.

Returns

Promise< boolean >

A promise resolving to a boolean indicating whether Ok was clicked or not.

Source: index.ts:279


message()

message(message, options?): Promise< void >

Shows a message dialog with an Ok button.

Example

import { message } from '@tauri-apps/plugin-dialog';
await message('Tauri is awesome', 'Tauri');
await message('File not found', { title: 'Tauri', type: 'error' });

Since

2.0.0

Parameters

ParameterTypeDescription
messagestringThe message to show.
options?string | MessageDialogOptionsThe dialog’s options. If a string, it represents the dialog title.

Returns

Promise< void >

A promise indicating the success or failure of the operation.

Source: index.ts:220


open()

open<T>(options = ...): Promise< OpenDialogReturn< T > >

Open a file/directory selection dialog.

The selected paths are added to the filesystem and asset protocol scopes. When security is more important than the easy of use of this API, prefer writing a dedicated command instead.

Note that the scope change is not persisted, so the values are cleared when the application is restarted. You can save it to the filesystem using tauri-plugin-persisted-scope.

Example

import { open } from '@tauri-apps/plugin-dialog';
// Open a selection dialog for image files
const selected = await open({
multiple: true,
filters: [
{
name: 'Image',
extensions: ['png', 'jpeg'],
},
],
});
if (Array.isArray(selected)) {
// user selected multiple files
} else if (selected === null) {
// user cancelled the selection
} else {
// user selected a single file
}

Example

import { open } from '@tauri-apps/plugin-dialog';
import { appDir } from '@tauri-apps/api/path';
// Open a selection dialog for directories
const selected = await open({
directory: true,
multiple: true,
defaultPath: await appDir(),
});
if (Array.isArray(selected)) {
// user selected multiple directories
} else if (selected === null) {
// user cancelled the selection
} else {
// user selected a single directory
}

Since

2.0.0

Type parameters

Parameter
T extends OpenDialogOptions

Parameters

ParameterType
optionsT

Returns

Promise< OpenDialogReturn< T > >

A promise resolving to the selected path(s)

Source: index.ts:161


save()

save(options = {}): Promise< string | null >

Open a file/directory save dialog.

The selected path is added to the filesystem and asset protocol scopes. When security is more important than the easy of use of this API, prefer writing a dedicated command instead.

Note that the scope change is not persisted, so the values are cleared when the application is restarted. You can save it to the filesystem using tauri-plugin-persisted-scope.

Example

import { save } from '@tauri-apps/plugin-dialog';
const filePath = await save({
filters: [
{
name: 'Image',
extensions: ['png', 'jpeg'],
},
],
});

Since

2.0.0

Parameters

ParameterType
optionsSaveDialogOptions

Returns

Promise< string | null >

A promise resolving to the selected path.

Source: index.ts:195


© 2024 Tauri Contributors. CC-BY / MIT