Reference

Toggle

A button that stays pressed while its state holds — bold in an editor, a filter that is on: aria-pressed, a press flipping bind:.

Toggle(_ label: String, bind: State, icon: String)

Since 6.2.0

label

icon

The quick brown fox

Example

wf

state bold = false state italic = true Row(gap: .sm) { Toggle("Bold", bind: bold, icon: "type") Toggle("Italic", bind: italic) } Text("The quick brown fox") { style { font-weight: {if bold { "700" } else { "400" }} font-style: {if italic { "italic" } else { "normal" }} } }

Without an icon

wf

state pinned = false Toggle("Pin to the sidebar", bind: pinned)

Props

Props of Toggle
PropTypeUnsetMeaning

label

String (positional)

—

Its words

bind:

State (required)

—

The Bool state it shows (aria-pressed) and flips on each press

icon:

String

none

An icon before the words, one of the built-in icon names

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.

No flags of its own.

Events

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

Slots

It takes no slots.

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