Reference

Listbox

A list of options always shown, one chosen (selection follows the arrow keys) or, .multiple, several: Space chooses, Shift with an arrow takes the next one in too, Ctrl or ⌘ with A takes them all; a letter goes to the next option that starts with it.

Listbox(bind: State, label: String, multiple: Bool) { … }

Since 6.2.0

label

multiple

Apple
Banana
Cherry
Mango

Chosen: apple

Example

wf

state fruit = "apple" Listbox(bind: fruit, label: "Fruit") { Listbox.Option("Apple", value: "apple") Listbox.Option("Banana", value: "banana") Listbox.Option("Cherry", value: "cherry") Listbox.Option("Mango", value: "mango") } Text("Chosen: {fruit}").muted

Several at once

wf

state toppings: [String] = ["cheese"] Listbox(bind: toppings, label: "Toppings").multiple { Listbox.Option("Cheese", value: "cheese") Listbox.Option("Mushrooms", value: "mushrooms") Listbox.Option("Olives", value: "olives") } Text("Chosen: {toppings.join(", ")}")

Props

Props of Listbox
PropTypeUnsetMeaning

bind:

State (required)

—

The state it reads and writes: the chosen option's value:, or with .multiple a list of them in the order they were chosen

label:

String (required)

—

What is being chosen: the list's accessible name (aria-label)

multiple:

Bool

false

Several at once: bind: is a list; Space toggles, Shift with an arrow takes the next one in, Ctrl/⌘+A all. Written as a flag, .multiple, or multiple: true.

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.

.multiple

Events

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

Slots

children

Parts

The parts of Listbox are written under its name, inside it. Each is described here, with what it takes.

Listbox.Option

One option: its words, and the value bind: holds when it is chosen.

Listbox.Option(_ label: String, value: String or Number or Bool, icon: String, aria-disabled: String) { … }
Props of Listbox.Option
PropTypeUnsetMeaning

label

String (positional)

—

The option's words; a letter typed goes to the next option they start with

value:

String or Number or Bool (required)

—

What bind: holds when it is chosen (or, with .multiple, what the list holds while it is chosen)

icon:

String

none

The name of a built-in icon drawn before its words

aria-disabled:

String

none

"true": shown, passed over by the arrow keys, never chosen

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