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
Chosen: apple
Example
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
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
| Prop | Type | Unset | Meaning |
|---|---|---|---|
bind: | State (required) | — | The state it reads and writes: the chosen option's |
label: | String (required) | — | What is being chosen: the list's accessible name ( |
multiple: | Bool | false | Several at once: |
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) { … }
| Prop | Type | Unset | Meaning |
|---|---|---|---|
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 |
icon: | String | none | The name of a built-in icon drawn before its words |
aria-disabled: | String | none |
|
Renders with the class wf-listbox, stable across releases, so a stylesheet may target it.