Dialogs and prompts

A dialog asks for a decision or a short piece of information before an app continues a task. It is useful when the answer affects what happens next, such as confirming a deletion or naming a new item.

An action opens the dialog and awaits the result; the app can then continue or cancel its work.

button(res::str::delete()).action(move || {
    day::task(async move {
        let choice = Alert::new(res::str::delete_title())
            .message(res::str::delete_body())
            .destructive(res::str::delete(), Choice::Delete) // a button carrying a payload
            .cancel(res::str::cancel()) // dismissal → None
            .present()
            .await; // -> Option<Choice>
        if choice == Some(Choice::Delete) {
            store.delete(id);
        }
    });
});

Use day::task to await a dialog from a synchronous action.

The UI snippets use generated res::str accessors from an app’s Fluent catalog; see the example messages and catalog setup.

Alerts, confirmations, and prompts

alert(res::str::saved()).present();                    // fire-and-forget notice (1 button)
let ok: bool         = confirm(res::str::quit()).await;
let name: Option<String> = prompt(res::str::name()).await; // -> Option<String>

// full builder: buttons carry a typed payload; `.cancel()` and dismissal → None
let picked: Option<Flavor> = Alert::new(res::str::pick())
    .button(res::str::vanilla(), Flavor::Vanilla)
    .button(res::str::pistachio(), Flavor::Pistachio)
    .sheet()                                       // bottom action sheet on mobile
    .cancel(res::str::cancel())
    .present().await;

Every text field is an IntoText, so titles and buttons accept generated res::str messages.

Toolkit implementations

Platform guidance: Apple: alerts; Android: dialogs; Windows: dialogs.

ToolkitDialog / sheetPrompt
appkitNSAlert + beginSheetModalForWindow: (async)NSAlert with an NSTextField accessory
uikitUIAlertController (.alert / .actionSheet) on the root VCUIAlertController + addTextField
gtkAdwAlertDialog (libadwaita 1.5; response signal)AdwAlertDialog with a GtkEntry extra-child
qtQMessageBox.open() + finished (shim)QInputDialog.getText (shim)
androidMaterialAlertDialogBuilder (buttons / setItems for sheets)M3 dialog + TextInputLayout
arkuiArkUI PromptAction.openCustomDialog modal with themed native Text / Button content; sheets align to the bottomSame modal host with native TextInput, initial value, placeholder and IME submit
mockrecords the spec; resolved programmaticallysame
WinUIContentDialogContentDialog + TextBox

The main loop keeps running while a dialog is open.

ArkUI

Dialogs use the primary window. Alerts support multiple buttons, destructive choices, scrolling content, and Back or outside dismissal. Action-sheet choices are vertical. A prompt returns Some("") for an accepted empty value and None for cancellation. The answer is delivered after the native dialog closes, so the continuation can open another.

Lifetime

Dialogs attach to the active window where supported. On ArkUI they use the primary window. Do not assume that disposing the initiating UI subtree cancels an outstanding dialog task. Check the app state again before applying its answer. See Async work for task ownership and cancellation.

Use file pickers for open/save operations and windows for additional app windows.