Reference

AlertDialog

A <dialog> that asks before something that cannot be undone: role="alertdialog", its body read out with its title, and closed by Escape or its own buttons, not a press outside. For a question asked from a handler, await ask(…) draws one.

AlertDialog(visible: State, title: String, dismiss: Enum, …) { … }

Since 6.2.0

title

dismiss

any

escape

none

Discard your changes?

Your 3 edits to the pricing page will be lost.

Draft: 3 unsaved edits

Example

wf

state sure = false state said = "Draft: 3 unsaved edits" Button("Discard changes").danger.outlined { on click { sure = true } } AlertDialog(visible: sure, title: "Discard your changes?") { Text("Your 3 edits to the pricing page will be lost.") AlertDialog.Footer { Button("Keep editing") { on click { sure = false } } Button("Discard").danger { on click { sure = false said = "Draft discarded" } } } } Text(said).muted

A heading with markup

wf

state sure = false Button("Delete branch") { on click { sure = true } } AlertDialog(visible: sure, title: "Delete the branch fix-login?") { AlertDialog.Title { Markdown("Delete the branch `fix-login`?") } AlertDialog.Footer { Button("Cancel") { on click { sure = false } } } }

Props

Props of AlertDialog
PropTypeUnsetMeaning

visible:

State

none: it never opens

Whether it is open: a Bool state, written back false when Escape, a press on the backdrop or its close button shuts it; a condition opens it but is not written

title:

String

none

The heading at the top, and the accessible name; a value that reads state follows it; a AlertDialog.Title block draws the heading instead

dismiss:

one of its cases

escape

What closes it besides the page's own button and visible:; an alert dialog is answered, so a press beside it does nothing unless it says .any. Written as a flag, .any, or by name, dismiss: .any.

  • .any: Escape, or a press outside it
  • .escape (the default): Escape only: a press outside is the page's
  • .none: Neither: only the page's own button closes it, for what must be answered

initialFocus:

Element

none

What takes the focus when it opens, by its ref:; unset, what says autofocus, else its first control; when it closes the focus goes back where it was

Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.

Flags and cases

A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.

.any

.escape

.none

Events

Events of AlertDialog
EventSendsMeaning
on close—

Every element also takes the props, the events and the attribute families listed on every element.

Slots

children

Parts

The parts of AlertDialog are written under its name, inside it. Each is described here, with what it takes.

AlertDialog.Title

What the alert dialog's heading draws, in place of its title:'s words, which stay its name.

AlertDialog.Title { … }

Its answers: the button that loses nothing first.

AlertDialog.Footer { … }

Renders with the class wf-dialog wf-alert-dialog, stable across releases, so a stylesheet may target it.