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

wf

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

wf

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

wf

Menu(trigger: "Share") { Menu.Item { Text("Copy link") } Menu.Item(disabled: true) { Text("Publish (owners only)") } }

Props

Props of Menu
PropTypeUnsetMeaning

trigger:

String

Menu (no button at all when visible: opens it)

The words on the button that opens it

label:

String

none

The menu list's accessible name (aria-label); it is not the button's words, which trigger: gives

visible:

State

false

A Bool state that opens and closes it: the button sets it, and Escape, a press outside or a choice write false. With no trigger:, state alone opens it

anchor:

Element or Point

its button

What it is placed against: an element's ref:, or a point { x: e.clientX, y: e.clientY }

at:

Point

none

A point to place it at, { x: e.clientX, y: e.clientY }: where the pointer asked for a context menu

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, .bottom, or by name, placement: .bottom.

  • .bottom: Below, centred
  • .bottomStart (the default): Below, lined up with its start edge (the right in a right-to-left page)
  • .bottomEnd: Below, lined up with its end edge
  • .top: Above, centred
  • .topStart: Above, lined up with its start edge
  • .topEnd: Above, lined up with its end edge
  • .left: To its left, centred
  • .leftStart: To its left, from its top
  • .leftEnd: To its left, to its bottom
  • .right: To its right, centred
  • .rightStart: To its right, from its top
  • .rightEnd: To its right, to its bottom

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

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

One entry of the menu; on click is what choosing it does.

Menu.Item(shortcut: String, checked: Bool, disabled: Bool, …) { … }
Props of Menu.Item
PropTypeUnsetMeaning

shortcut:

String

none

The keys that do the same, mod+b, shown at its end as this system writes them (⌘B, Ctrl+B); in a Menubar the keys also run it

checked:

Bool

none: a plain item

A check mark that follows the value (menuitemcheckbox, aria-checked): the item turns something on and off. Written as a flag, .checked, or checked: true.

disabled:

Bool

false

Shown dimmed (aria-disabled), skipped by the arrow keys, and cannot be chosen. Written as a flag, .disabled, or disabled: true.

danger:

Bool

false

What it does cannot be taken back — Delete, Discard: drawn in the danger colour. Written as a flag, .danger, or danger: true.

.checked

.disabled

.danger

An entry that opens a menu of its own beside it.

Menu.Sub(label: String) { … }
Props of Menu.Sub
PropTypeUnsetMeaning

label:

String

empty

The words of the entry that opens its menu beside it

A rule between groups of entries.

Menu.Divider

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