Components
Documentation content

Checkbox

Use checkbox for a boolean value. The element content or text supplies the visible label; label supplies an accessible name without drawing text. Bind checked to the model and handle on-toggle in update. Use radio to select one option, or switch for a sliding on/off control.

checkbox
Checkboxes rendered by the engine (light theme)
checked, unchecked, and disabled checkboxes

Markup

<column gap="12">
  <checkbox checked="{accepted}" on-toggle="toggle_terms">Accept terms and conditions</checkbox>
  <checkbox checked="{reports}" on-toggle="toggle_reports">Send usage reports</checkbox>
  <checkbox checked="true" disabled="true">Managed by your organization</checkbox>
</column>

Store a boolean in the model and toggle it in update:

// model: { readonly accepted: boolean }
case "toggle_terms":
  return { ...model, accepted: !model.accepted };
// model: accepted: bool = false,
.toggle_terms => model.accepted = !model.accepted,

Programmatic construction (Zig)

In a Zig view, the canvas.Ui builder constructs the same tree programmatically:

ui.column(.{ .gap = 12 }, .{
    ui.checkbox(.{ .text = "Accept terms and conditions", .checked = model.accepted, .on_toggle = .toggle_terms }),
    ui.checkbox(.{ .text = "Send usage reports", .checked = model.reports, .on_toggle = .toggle_reports }),
    ui.checkbox(.{ .text = "Managed by your organization", .checked = true, .disabled = true }),
})

Attributes

AttributeDescription
textText value for text-bearing elements; a literal or one {binding}.
checkedChecked state for checkbox/toggle; true/false or a {binding}.
disabledDisables the control; true/false or a {binding}.
on-toggleDispatch a Msg on toggle: tag or tag:{payload}. Hit-target elements only (checkbox, toggle, toggle-button, switch, accordion, ...).