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.
| Toolkit | Dialog / sheet | Prompt |
|---|---|---|
| appkit | NSAlert + beginSheetModalForWindow: (async) | NSAlert with an NSTextField accessory |
| uikit | UIAlertController (.alert / .actionSheet) on the root VC | UIAlertController + addTextField |
| gtk | AdwAlertDialog (libadwaita 1.5; response signal) | AdwAlertDialog with a GtkEntry extra-child |
| qt | QMessageBox.open() + finished (shim) | QInputDialog.getText (shim) |
| android | MaterialAlertDialogBuilder (buttons / setItems for sheets) | M3 dialog + TextInputLayout |
| arkui | ArkUI PromptAction.openCustomDialog modal with themed native Text / Button content; sheets align to the bottom | Same modal host with native TextInput, initial value, placeholder and IME submit |
| mock | records the spec; resolved programmatically | same |
| WinUI | ContentDialog | ContentDialog + 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.