Reference
Select
Drop-down of Select.Option children.
Select(bind: State, value: String or Number, label: String, …) { … }
Before 5.0
label
hint
disabled
multiple
Where your data is stored.
Chosen: eu-west
Example
state region = "eu-west"
Select(bind: region, label: "Region", hint: "Where your data is stored.") {
Select.Option("Europe (Ireland)", value: "eu-west")
Select.Option("US East (Virginia)", value: "us-east")
Select.Option("Asia Pacific (Tokyo)", value: "ap-northeast")
}
Text("Chosen: {region}").muted
With an error message
state role = ""
derived roleError = if role == "" { "Choose a role for this person." } else { "" }
Select(bind: role, label: "Role", error: roleError) {
Select.Option("Choose…", value: "")
Select.Option("Viewer", value: "viewer")
Select.Option("Editor", value: "editor")
Select.Option("Owner", value: "owner")
}
Disabled
state plan = "team"
Select(bind: plan, label: "Plan").disabled {
Select.Option("Free", value: "free")
Select.Option("Team", value: "team")
}
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
bind: | State | The state it reads and writes: the chosen option's | |
value: | String or Number | the first option | The option chosen at first, by its value, when no state is bound |
label: | String | none | Visible label; also the control's accessible name |
hint: | String | none | Help text under the control, linked to it by |
error: | String | none | Error text (a string; empty when there is none): announced as it appears and sets |
disabled: | Bool | false | Whether the control is inert: it cannot be focused or changed, and a form does not send it. Written as a flag, |
multiple: | Bool | false | A list box that takes several choices; a bound |
Attribute families: global, aria, data, input. 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.
.disabled
.multiple
Events
The DOM events it is drawn to answer. Any other DOM event works too, in an on … { } handler.
| Event | Sends | Meaning |
|---|---|---|
on change | DOM | The value was committed |
on focus | DOM | The element received focus |
on blur | DOM | The element lost focus |
Every element also takes the props, the events and the attribute families listed on every element.
Slots
children
Parts
The parts of Select are written under its name, inside it. Each is described here, with what it takes.
Select.Option
One choice: the visible label, and the value sent with the form.
Select.Option(_ label: String, value: String or Number or Bool)
| Prop | Type | Unset | Meaning |
|---|---|---|---|
label | String (positional) | — | The words the option shows; also its value when it has no |
value: | String or Number or Bool | its label | What |
Renders with the class wf-select, stable across releases, so a stylesheet may target it.