Reference
Modal
Modal <dialog>, opened by a state flag; the browser supplies focus trapping and Escape. on close runs when it closes, however it was closed, and the focus goes back to what had it.
Modal(visible: State, title: String, closable: Bool, …) { … }
Before 5.0
title
dismiss
any
escape
none
Report: Q3 report
Example
state open = false
state name = "Q3 report"
Button("Rename") { on click { open = true } }
Modal(visible: open, title: "Rename the report").closable {
on close { open = false }
Input(bind: name, label: "Name")
Modal.Footer {
Button("Cancel") { on click { open = false } }
Button("Save").primary { on click { open = false } }
}
}
Text("Report: {name}").muted
Escape only, focus on a field
state open = false
state email = ""
Button("Invite") { on click { open = true } }
Modal(visible: open, title: "Invite a teammate", dismiss: .escape, initialFocus: emailField) {
Input(bind: email, label: "Email", ref: emailField).email
Modal.Footer { Button("Send invite").primary { on click { open = false } } }
}
A heading with markup
state open = false
Button("Delete") { on click { open = true } }
Modal(visible: open, title: "Delete deploys.wf?").closable {
Modal.Title { Markdown("Delete `deploys.wf`?") }
Text("This cannot be undone.")
Modal.Footer { Button("Delete").danger { on click { open = 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 Modal are written under its name, inside it. Each is described here, with what it takes.
Modal.Title
What the modal's heading draws, in place of its title:'s words, which stay its name: Modal.Title { Text { "Rename " Code(name) } }.
Modal.Title { … }
Modal.Footer
The modal's action row.
Modal.Footer { … }
Renders with the class wf-modal, stable across releases, so a stylesheet may target it.