RadioGroup
The exclusive choice: labeled circles, exactly one selected.
Options carry their own Description and Disabled flag;
clicks are processed at the top of Layout, so the click's own frame renders the new selection.
Like every choice component, the selection is a VALUE: the cursor is
unexported, Value()/SetValue() read and write it, the zero value picks
the first option, and an unknown value clears rather than falling back to option 0 — see
Select for the full contract.
Installation
Use the module import (the default), or own the source: lotusui add
vendors the component into your app and lotusui update keeps the copy mergeable —
see Registry.
go get github.com/ikaito-com/lotusui
# or vendor the source into your app:
go run github.com/ikaito-com/lotusui/cmd/lotusui add radio-group
Usage
density := lotusui.RadioGroup{
Options: lotusui.RadioOpts("Default", "Comfortable", "Compact"),
}
density.SetValue(stored) // an unknown value clears, never picks option 0
density.Layout(th, gtx)
stored = density.Value()
Disabled option
plans := lotusui.RadioGroup{Options: []lotusui.RadioOption{
{Label: "Starter", Value: "starter"},
{Label: "Pro (contact sales)", Value: "pro", Disabled: true},
{Label: "Enterprise", Value: "enterprise"},
}}
Description
Each option's Description renders muted under its label.
density := lotusui.RadioGroup{Options: []lotusui.RadioOption{
{Label: "Default", Value: "default", Description: "Standard spacing for most use cases."},
{Label: "Comfortable", Value: "comfortable", Description: "More space between elements."},
{Label: "Compact", Value: "compact", Description: "Dense layout for scanning lots of data."},
}}
Invalid
Invalid renders danger rings; pair it with a Field error.
prefs := lotusui.RadioGroup{Invalid: true}
API
| Option | Type | Description |
|---|---|---|
Options | []RadioOption | The choices: Label, Value, Description (muted sub-label) and Disabled. RadioOpts("a","b") builds label-only lists. |
Value() / SetValue(v) | string | The chosen option's value; SetValue with an unknown value clears. |
Clear() / Chosen() | method | Drop the choice; whether anything is chosen. |
Size | Size | The shared size presets scale the circles. |
Invalid | bool | Danger chrome on the circles. |