Radio Group

One choice among a few visible options.

Plan
Up to 3 members and 250 issues.
Unlimited issues, cycles and guests.
Single sign-on and audit logs. Talk to sales.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/radio-group

Usage

import { RadioGroup } from "./ui/uicontext/components/RadioGroup.ts"
const Message = UiSchema.TaggedEnum({ PickedDensity: { value: Schema.String } })export const DensityPicker = (h: Html.H<typeof Message.Type>, density: string) =>	RadioGroup(h, {		id: "row-density",		label: "Row density",		value: density,		options: [			{ value: "compact", label: "Compact" },			{ value: "comfortable", label: "Comfortable" },		],		onPick: (value) => Message.PickedDensity({ value }),	})

Examples

Nothing picked yet

With value: null no option is picked. Inside a FormField with group: true, the label names the group and the error marks every option.

Who can see this project?

You can change this later.

In a row, and read-only

A row of short options wraps on a narrow screen. Read-only keeps the arrow keys working but picks nothing.

Row density
Workspace default (set by an owner)

API reference

Options

RadioGroup options
NameTypeDefaultDescription
idrequiredstring—The group's id; each option's description is identified from it
keystring—Names the group among others in the same view; needed for more than one
valuerequiredstring | null—The picked option's value, or null when none is picked yet. The caller keeps it.
optionsrequiredRadioOption[]—The choices, each with a value, a label and an optional description.
onPickrequired(value: string) => Message—What a pick asks for: the value to store and pass back as value
labelstring—A visible name above the options; leave it out inside a FormField
ariaLabelstring—The accessible name when there's no visible label
orientation"vertical" | "horizontal"verticalStacked or in a row; arrow keys move along either way; vertical by default.
disabledboolean—No option can be picked or focused.
readOnlyboolean—Shows the pick and stays navigable, but no option can be picked.
requiredboolean—An option must be picked before its form submits.
namestring—The form field: the picked value submits under name
fieldFieldControlAttrs—A FormField's attributes: its label names the group, its description and error describe it
styleStyle—StyleX styles applied after the group’s own.

Accessibility

  • A radio group and one Tab stop: the arrow keys move between options and pick as they go, and Space picks.
  • The group is named by its label and each option is described by its own description. Disabled options are skipped.

Source