Skip to Content
Onevra

Radio

Chooses one value from a small set, all visible at once.

Loading the live example…

radio.go
import (
	"github.com/egoist/mygo/ui"
	"github.com/oneo-me/onevra/source/components"
)

type shipping struct {
	method string
}

func (s *shipping) View(c *ui.Context) {
	ui.Column(c).Gap(12).Children(func() {
		components.Radio(c, &s.method, "standard", "Standard, 3–5 days")
		components.Radio(c, &s.method, "express", "Express, next day")
		components.Radio(c, &s.method, "pickup", "Pick up in store")
	})
}
Source

components.Radio is generic: each button writes its value into the shared *T when chosen. For longer lists, use a select.

API

Radio

func Radio[T comparable](c *ui.Context, selected *T, value T, label string) ui.Element

Radio creates a radio button that selects value into *selected, with a label. The label is also the accessible name.

pkg.go.dev
Edit this page on GitHub

On this page