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

Leave without saving?

Your draft of notes.md has changes that are not saved.

Example

wf

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

wf

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

wf

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

Props of Dialog
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 Dialog.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 Dialog
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 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.