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

Rename the report

Report: Q3 report

Example

wf

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

wf

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

wf

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

Props of Modal
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 Modal.Title block draws the heading instead

closable:

Bool

false

A close button (×) in the heading row, which closes it as Escape does; with no title: the row holds the button alone. Written as a flag, .closable, or closable: true.

dismiss:

one of its cases

any

What closes it besides the page's own button and visible:. Written as a flag, .any, or by name, dismiss: .any.

  • .any (the default): Escape, or a press outside it
  • .escape: 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.

.closable

.any

.escape

.none

Events

Events of Modal
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 Modal are written under its name, inside it. Each is described here, with what it takes.

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 { … }

The modal's action row.

Modal.Footer { … }

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