Reference
ToggleGroup
Buttons of which one is chosen — a view switcher, a segmented control — or, .multiple, several: one stop for Tab, the arrow keys inside it, each aria-pressed. bind: holds the chosen value: (a list with .multiple).
ToggleGroup(bind: State, label: String, multiple: Bool) { … }
Since 6.2.0
label
multiple
Showing the grid view
Example
state view = "grid"
ToggleGroup(bind: view, label: "View") {
ToggleGroup.Item("Grid", value: "grid", icon: "grid")
ToggleGroup.Item("List", value: "list", icon: "list")
}
Text("Showing the {view} view").muted
Several at once
state styles: [String] = ["b"]
ToggleGroup(bind: styles, label: "Text style").multiple {
ToggleGroup.Item("Bold", value: "b")
ToggleGroup.Item("Italic", value: "i")
ToggleGroup.Item("Underline", value: "u")
}
Text("{styles.length} on")
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
bind: | State (required) | — | The chosen item's |
label: | String (required) | — | What the group chooses: its 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 ToggleGroup are written under its name, inside it. Each is described here, with what it takes.
ToggleGroup.Item
One choice: its words, and the value bind: holds when it is chosen.
ToggleGroup.Item(_ label: String, value: String or Number or Bool, icon: String, disabled: Bool)
| Prop | Type | Unset | Meaning |
|---|---|---|---|
label | String (positional) | — | Its words |
value: | String or Number or Bool (required) | — | What |
icon: | String | none | An icon before the words, one of the built-in icon names |
disabled: | Bool | false | Whether the item is inert: it cannot be pressed and the arrow keys pass over it. Written as a flag, |
.disabled
Renders with the class wf-toggle-group, stable across releases, so a stylesheet may target it.