Skip to content

Radio: radio buttons

Build radio buttons with Radio. 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 (
	"github.com/dxui-org/dxui"
	"log"
)

func main() {
	choice := "small"
	app := dxui.NewApp(dxui.AppOptions{
		Title:      "Radio",
		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.Radio(
					dxui.RadioProps{
						Selected: choice == "small",
						OnSelect: func() {
							choice = "small"
						},
					},
					dxui.Label("Small"),
				),
				dxui.Radio(
					dxui.RadioProps{
						Selected: choice == "large",
						OnSelect: func() {
							choice = "large"
						},
					},
					dxui.Label("Large"),
				),
				dxui.Label(choice),
			),
		)
	}); err != nil {

		log.Fatal(err)
	}
}

Parameters and API

go
func Radio(props RadioProps, 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.
SelectedboolSelected state, default false; derive it from a shared application value.
DisabledboolDefaults to false; true removes focus and cancels interaction on interactive components.
OnSelectfunc()Called without arguments when an enabled unselected Radio activates; update the shared value in the app.

Behavior and limitations

Selected is authoritative. Pointer or Space calls OnSelect only when enabled and unselected; a selected item neither deselects nor calls back. Use shared application state for exclusivity; there is no RadioGroup. Every Radio keeps its own focus stop.

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