Reference
Menu
A menu above everything: opened by its trigger: button, or by visible: at an anchor: or a point at: — a context menu. Escape, a press outside or a choice close it, write false back to visible: and fire on close.
Menu(trigger: String, label: String, visible: State, …) { … }
Before 5.0
trigger
placement
bottom
bottomStart
bottomEnd
top
topStart
Nothing chosen yet
Example
state said = "Nothing chosen yet"
state pinned = false
Menu(trigger: "File actions").bottomStart {
Menu.Item(shortcut: "F2") {
on click { said = "Rename" }
Text("Rename")
}
Menu.Item(shortcut: "mod+d") {
on click { said = "Duplicate" }
Text("Duplicate")
}
Menu.Item(checked: pinned) {
on click { pinned = !pinned }
Text("Pinned")
}
Menu.Sub(label: "Move to") {
Menu.Item { on click { said = "Moved to Archive" } Text("Archive") }
Menu.Item { on click { said = "Moved to Drafts" } Text("Drafts") }
}
Menu.Divider
Menu.Item(shortcut: "mod+backspace").danger {
on click { said = "Delete" }
Text("Delete")
}
}
Text(said).muted.sm
A context menu, opened by state at a point
state asked = false
state point = { x: 0, y: 0 }
Card {
on contextmenu(e) { e.preventDefault() point = { x: e.clientX, y: e.clientY } asked = true }
Text("Right-click here")
}
Menu(visible: asked, at: point) {
Menu.Item { Text("Copy") }
Menu.Item { Text("Paste") }
}
A disabled item
Menu(trigger: "Share") {
Menu.Item { Text("Copy link") }
Menu.Item(disabled: true) { Text("Publish (owners only)") }
}
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
trigger: | String |
| The words on the button that opens it |
label: | String | none | The menu list's accessible name ( |
visible: | State | false | A Bool state that opens and closes it: the button sets it, and Escape, a press outside or a choice write |
anchor: | Element or Point | its button | What it is placed against: 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 to stay on screen. Written as a flag,
|
offset: | Number | 4 | The gap between it and its anchor, in px |
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
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 Menu are written under its name, inside it. Each is described here, with what it takes.
Menu.Item
One entry of the menu; on click is what choosing it does.
Menu.Item(shortcut: String, checked: Bool, disabled: Bool, …) { … }
| Prop | Type | Unset | Meaning |
|---|---|---|---|
shortcut: | String | none | The keys that do the same, |
checked: | Bool | none: a plain item | A check mark that follows the value ( |
disabled: | Bool | false | Shown dimmed ( |
danger: | Bool | false | What it does cannot be taken back — Delete, Discard: drawn in the danger colour. Written as a flag, |
.checked
.disabled
.danger
Menu.Sub
An entry that opens a menu of its own beside it.
Menu.Sub(label: String) { … }
| Prop | Type | Unset | Meaning |
|---|---|---|---|
label: | String | empty | The words of the entry that opens its menu beside it |
Menu.Divider
A rule between groups of entries.
Menu.Divider
Renders with the class wf-menu, stable across releases, so a stylesheet may target it.