Reference
Dialog
Confirmation <dialog>, opened by a state flag. on close runs when it closes, however it was closed, and the focus goes back to what had it.
Dialog(visible: State, title: String, closable: Bool, …) { … }
Before 5.0
title
dismiss
any
escape
none
Example
state asking = false
Button("Close the editor") { on click { asking = true } }
Dialog(visible: asking, title: "Leave without saving?").closable {
Text("Your draft of notes.md has changes that are not saved.")
Row(gap: .sm, justify: .end) {
Button("Stay") { on click { asking = false } }
Button("Leave").danger { on click { asking = false } }
}
}
A heading with markup
state asking = false
Button("Leave") { on click { asking = true } }
Dialog(visible: asking, title: "Leave without saving notes.md?") {
Dialog.Title { Markdown("Leave without saving `notes.md`?") }
Button("Stay") { on click { asking = false } }
}
Must be answered
state asking = false
Button("Sign out") { on click { asking = true } }
Dialog(visible: asking, title: "Sign out of every device?", dismiss: .none) {
Button("Sign out").primary { on click { asking = 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 |
closable: | Bool | false | A close button (×) in the heading row, which closes it as Escape does; with no |
dismiss: | one of its cases | any | 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.
.closable
.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 Dialog are written under its name, inside it. Each is described here, with what it takes.
Dialog.Title
What the dialog's heading draws, in place of its title:'s words, which stay its name.
Dialog.Title { … }
Renders with the class wf-dialog, stable across releases, so a stylesheet may target it.