Reference
Checkbox
Checkbox bound to a boolean state.
Checkbox(bind: State, checked: Bool, label: String, …)
Before 5.0
checked
label
disabled
Accept the terms to go on.
Example
state terms = false
state newsletter = true
Stack(gap: .sm) {
Checkbox(bind: terms, label: "I accept the terms of service")
Checkbox(bind: newsletter, label: "Send me the monthly newsletter")
Text(if terms { "Ready to sign up." } else { "Accept the terms to go on." }).muted
}
Disabled
state backups = true
Checkbox(bind: backups, label: "Daily backups (included in your plan)").disabled
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
bind: | State | The | |
checked: | Bool | false | Whether it is ticked, when no state is bound: shown, not written back — handle |
label: | String | none | The words after the box, which a press on also ticks; also its accessible name |
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, |
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.
.checked
.disabled
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 |
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-checkbox, stable across releases, so a stylesheet may target it.