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
Draft: 3 unsaved edits
Example
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
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
| Prop | Type | Unset | Meaning |
|---|---|---|---|
visible: | State | none: it never opens | Whether it is open: a |
title: | String | none | The heading at the top, and the accessible name; a value that reads state follows it; a |
dismiss: | one of its cases | escape | What closes it besides the page's own button and
|
initialFocus: | Element | none | What takes the focus when it opens, by its |
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
| Event | Sends | Meaning |
|---|---|---|
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 { … }
AlertDialog.Footer
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.