Skip to content

Checkbox

A checkbox lets the user switch a boolean value on or off without an immediate effect, e.g. in a form which is submitted later. Bind it to a *core.State[bool] with InputValue and pass the current value to the constructor. In forms you usually want the Checkbox Field, which adds a label. For settings which take effect immediately, use a Toggle.

Checkbox

checked := core.AutoState[bool](wnd).Init(func() bool { return true })

HStack(
	Checkbox(checked.Get()).InputValue(checked),
	Checkbox(false),
	Checkbox(true).Disabled(true),
).Gap(L16)

Constructors

ConstructorDescription
func Checkbox(checked bool) TCheckboxCreates a checkbox with the given value.

Methods

MethodDescription
Disabled(disabled bool) TCheckboxDisabled enables or disables user interaction with the checkbox.
ID(id string) TCheckboxID assigns a unique identifier to the checkbox, useful for testing or referencing.
InputChecked(input *core.State[bool]) TCheckboxDeprecated: use InputValue.
InputValue(input *core.State[bool]) TCheckboxInputValue binds the checkbox to an external boolean state, allowing it to be controlled from outside the component.
Name(name string) TCheckboxName defines the name of the checkbox.
Visible(v bool) TCheckboxVisible controls the visibility of the checkbox; setting false hides it.

Related