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
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
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
| Prop | Type | Unset | Meaning |
|---|---|---|---|
visible: | State | none: it never opens | Whether it is open: a |
anchor: | Element or Point | none | What it is placed against and follows as the page scrolls: an element's |
at: | Point | none | A point to place it at, |
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,
|
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 |
arrow: | Bool | false | A small point on the side toward its anchor, following the placement it lands on. Written as a flag, |
dismiss: | one of its cases | any | What closes it besides
|
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.
.bottom
.bottomStart
.bottomEnd
.top
.topStart
.topEnd
.left
.leftStart
.leftEnd
.right
.rightStart
.rightEnd
.arrow
.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
Renders with the class wf-popover, stable across releases, so a stylesheet may target it.