Reference

Popover

A layer at a control: drawn above everything, placed against its anchor:, closed by Escape or a press outside, which write false back to visible: and fire on close.

Popover(visible: State, anchor: Element or Point, at: Point, …) { … }

Since 5.9.0

placement

bottom

bottomStart

bottomEnd

top

topStart

label

dismiss

any

escape

none

Example

wf

state open = false state branch = "main" Button("Branch: {branch}", ref: branchBtn) { on click { open = !open } } Popover(visible: open, anchor: branchBtn, placement: .bottomStart, label: "Branches").arrow { on close(reason) { open = false } Stack(gap: .xs) { Button("main") { on click { branch = "main" open = false } } Button("release-7.0") { on click { branch = "release-7.0" open = false } } Button("fix-login") { on click { branch = "fix-login" open = false } } } }

Above, closed by its own button only

wf

state open = false Button("Share", ref: shareBtn) { on click { open = true } } Popover(visible: open, anchor: shareBtn, placement: .top, label: "Share", dismiss: .none) { Text("Anyone with the link can view.") Button("Done") { on click { open = false } } }

Props

Props of Popover
PropTypeUnsetMeaning

visible:

State

none: it never opens

Whether it is open: a Bool state, written back false when Escape or a press outside closes it (as dismiss: allows); a condition opens it but is not written

anchor:

Element or Point

none

What it is placed against and follows as the page scrolls: an element's ref:, or a point { x: e.clientX, y: e.clientY }; its control gets aria-controls and aria-expanded

at:

Point

none

A point to place it at, { x: e.clientX, y: e.clientY } — where the pointer asked for a context menu; the same option as anchor:, so give one or the other

placement:

one of its cases

bottomStart

Where it goes against its anchor; it flips to the other side when there is no room, and slides along its side to stay on screen. Written as a flag, .bottom, or by name, placement: .bottom.

  • .bottom: Below, centred
  • .bottomStart (the default): Below, from its start
  • .bottomEnd: Below, to its end
  • .top: Above, centred
  • .topStart: Above, from its start
  • .topEnd: Above, to its end
  • .left: Before it, centred
  • .leftStart: Before it, from its top
  • .leftEnd: Before it, to its bottom
  • .right: After it, centred
  • .rightStart: After it, from its top
  • .rightEnd: After it, to its bottom

offset:

Number

6

The gap between it and its anchor, in px

label:

String

none

Its accessible name; one drawn as a dialog (no other role:) without it is A18

arrow:

Bool

false

A small point on the side toward its anchor, following the placement it lands on. Written as a flag, .arrow, or arrow: true.

dismiss:

one of its cases

any

What closes it besides visible:; on close hears "escape" or "outside". 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, its first control, else the popover itself

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.

.bottom

.bottomStart

.bottomEnd

.top

.topStart

.topEnd

.left

.leftStart

.leftEnd

.right

.rightStart

.rightEnd

.arrow

.any

.escape

.none

Events

Events of Popover
EventSendsMeaning
on close—

Every element also takes the props, the events and the attribute families listed on every element.

Slots

children

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