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

wf

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

wf

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

Props of ToggleGroup
PropTypeUnsetMeaning

bind:

State (required)

—

The chosen item's value: (pressing the chosen one again keeps it), or with .multiple a list of them, each press adding or taking one

label:

String (required)

—

What the group chooses: its accessible name (aria-label)

multiple:

Bool

false

Several at once: bind: holds a list. 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 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)
Props of ToggleGroup.Item
PropTypeUnsetMeaning

label

String (positional)

—

Its words

value:

String or Number or Bool (required)

—

What bind: holds (or its list contains) while it is chosen; it is drawn pressed then

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, or disabled: true.

.disabled

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