Skip to content

RadioGroup

KeyAction
/ kMove focus up
/ jMove focus down
SpaceSelect focused option

Enter is reserved for form submission.

RadioGroup implements FormField. The bound value type is string (the selected option’s value). SetFieldValue accepts a string matched against option values.

RadioGroup preview

RadioGroup is a single-choice option group. It implements IndexedValueProvider[string].

Constructor func NewRadioGroup(name string) *RadioGroup

Usage

radio := components.NewRadioGroup("plan").
SetLabel("Plan").
SetOptions([]string{"Free", "Pro", "Enterprise"}).
SetSelected(1)
radio.SetOnChange(func(e *components.ChangeEvent[string]) {
fmt.Println("selected:", e.NewValue)
})
fmt.Println(radio.Value())

Methods

Method Signature Description
Clear func (r *RadioGroup) Clear() Clear resets the selection to none.
ClearField func (r *RadioGroup) ClearField() ClearField resets the selection. Implements FormField.
FieldValue func (r *RadioGroup) FieldValue() any FieldValue returns the selected option label as an any. Implements FormField.
GetFieldHeight func (r *RadioGroup) GetFieldHeight() int GetFieldHeight returns the preferred height for this field.
GetName func (r *RadioGroup) GetName() string GetName returns the field name.
GetOptions func (r *RadioGroup) GetOptions() []string GetOptions returns the available options.
GetValue func (r *RadioGroup) GetValue() string GetValue returns the selected value.
HasValue func (r *RadioGroup) HasValue() bool HasValue returns true if an option is selected.
SelectedIndex func (r *RadioGroup) SelectedIndex() int SelectedIndex returns the selected index (-1 if none).
SetFieldValue func (r *RadioGroup) SetFieldValue(value any) error SetFieldValue sets the radio group's value from an any. Accepts a string (matched against option labels) or an int (option index). Implements FormField.
SetLabel func (r *RadioGroup) SetLabel(label string) *RadioGroup SetLabel sets the group label.
SetOnChange func (r *RadioGroup) SetOnChange(handler ChangeHandler[string]) *RadioGroup SetOnChange sets the change handler (new API).
SetOptions func (r *RadioGroup) SetOptions(options []string) *RadioGroup SetOptions sets the available options.
SetSelected func (r *RadioGroup) SetSelected(index int) *RadioGroup SetSelected sets the selected index.
SetSelectedIndex func (r *RadioGroup) SetSelectedIndex(index int) error SetSelectedIndex sets the selected index, returning an error if out of range.
SetSelectedValue func (r *RadioGroup) SetSelectedValue(value string) error SetSelectedValue sets the selected option by value.
Value func (r *RadioGroup) Value() string Value returns the selected value. This method is part of the ValueProvider interface.

Types

type ChangeHandler ChangeHandler handles value changes