Skip to content

Checkbox: checkboxes

Build checkboxes with Checkbox. This page includes a runnable example, all props, and behavior constraints.

Complete example

Complete environment setup first. Copy this complete main.go and run go run ..

go
package main

import (
	"fmt"
	"github.com/dxui-org/dxui"
	"log"
)

func main() {
	checked := false
	app := dxui.NewApp(dxui.AppOptions{
		Title:      "Checkbox",
		Width:      640,
		Height:     480,
		Background: dxui.RGBA(248, 250, 252, 255),
	})
	if err := app.Run(func() dxui.View {
		return dxui.Box(
			dxui.BoxProps{
				Gap: 16,
				Style: dxui.Style{
					Padding: dxui.Padding(24),
				},
			},
			dxui.Box(
				dxui.BoxProps{
					Gap: 12,
				},
				dxui.Checkbox(
					dxui.CheckboxProps{
						Checked:  checked,
						OnChange: dxui.Assign(&checked),
					},
					dxui.Label("Accept terms"),
				),
				dxui.Label(fmt.Sprint(checked)),
			),
		)
	}); err != nil {

		log.Fatal(err)
	}
}

Parameters and API

go
func Checkbox(props CheckboxProps, label View) View
FieldTypePurpose, defaults, and constraints
KeystringStable unique identity within one parent; empty by default. Use business IDs in dynamic lists, not changing indices.
StyleStyleLocal layout, paint, and text styling; zero uses intrinsic sizes and theme defaults.
TokenComponentTokenComponent theme entry; empty selects its default.
StatesStateStylesPaint patches for actual interaction states; cannot fabricate state or change layout.
PointerPointerBehaviorDefaults to PointerAuto; PointerNone excludes the entire subtree from pointer participation, unlike Disabled.
CheckedboolControlled boolean, default false; accept changes in OnChange.
DisabledboolDefaults to false; true removes focus and cancels interaction on interactive components.
OnChangefunc(bool)Proposes a complete new value; write it to state for the next build. See behavior for nil callbacks.

Behavior and limitations

Accepts one label View. Checked is controlled; pointer or Space proposes toggling it. Nil OnChange does not change the business value and is not Disabled. Disabled removes focus and cancels pressing. No tri-state support.

All components share identity, style, and pointer rules. See full declarations for referenced enums, structs, and comments. Running examples explains build verification.