npx shadcn@4.23.1 add @goop/trail-radio-groupRadio group
FreeA named group of options of which exactly one is chosen, for React and Tailwind CSS. Free, MIT.
What an agent sees
- RadioGroupItemOne option's radio, inside a RadioGroupLabel with its words
- RadioGroupLabelOne option's clickable row
import { RadioGroup, RadioGroupItem, RadioGroupLabel } from '@/components/ui/goop/radio-group';
<RadioGroup aria-label="Start the week on" defaultValue="monday">
<RadioGroupLabel>
<RadioGroupItem value="monday" /> Monday
</RadioGroupLabel>
<RadioGroupLabel>
<RadioGroupItem value="sunday" /> Sunday
</RadioGroupLabel>
</RadioGroup>Pick a plan with the pointer or the arrow keys and save it: the button is busy for a moment, then the current plan changes. The Free plan is refused, with the reason, for a workspace of five members. Look switches a plan chosen, none chosen yet, the Free plan off, or a plan whose words wrap; Orientation lays the plans in a row; Disabled turns the group off. The save is a timer; the five members and the plans are our own sample.
When to use
- A named group of options of which exactly one is chosen.
- Also called: radio buttons.
When not to use
- For a few short options that apply at once use SegmentedControl.
Installation
Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same Radio group on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing.
npx shadcn@4.23.1 add @goop/trail-radio-groupAdd the Goop Radio group to this project. The install steps are at https://goop.so/docs/install.mdUsage
import { RadioGroup, RadioGroupItem, RadioGroupLabel } from '@/components/ui/goop/radio-group';
<RadioGroup aria-label="Start the week on" defaultValue="monday">
<RadioGroupLabel>
<RadioGroupItem value="monday" /> Monday
</RadioGroupLabel>
<RadioGroupLabel>
<RadioGroupItem value="sunday" /> Sunday
</RadioGroupLabel>
</RadioGroup>- Fits: flow (its recipe).
- In a form, give the group a
Field orientation="vertical"or a heading of its own, never a settings row. - height, width, padding, gap, corner, border, background, text, motion: add no class for these.
API reference
| Option | Type | What it does |
|---|---|---|
| value? | string | The chosen option's value, for a group its caller holds (with onValueChange). |
| defaultValue? | string | The option chosen at first render, for a group that holds its own choice. |
| onValueChange? | (value: string) => void | Called with the option's value whenever a person chooses one. |
| name? | string | The group's name, sent with the form; its own when left out. |
| disabled? | boolean = false | Every option off: none takes the focus, a click or a key. |
| required? | boolean = false | A form with this group cannot be sent until an option is chosen. |
| orientation? | 'vertical' | 'horizontal' = 'vertical' | The options as a column or a row that wraps. |
- State: value (value / defaultValue / onValueChange); drawn by data-disabled
| Part | What it is |
|---|---|
| RadioGroupItem | One option's radio, inside a RadioGroupLabel with its words; value is what the group reports; value: string — The value the group reports and sends when this option is chosen; also takes onChange?: (event: ChangeEvent<HTMLInputElement>) => void; required?: boolean; disabled?: boolean; form?: string |
| RadioGroupLabel | One option's clickable row; put its RadioGroupItem in it first, then the option's words; also takes htmlFor?: string |
- data-slot values (to select a part by): radio-group, radio-group-item, radio-group-label
Keyboard
| Key | What it does |
|---|---|
| ArrowUp ArrowDown ArrowLeft ArrowRight | Move selection |
| Space | Choose focused |
Accessibility
- The native element answers the keyboard.
- focus-visible, checked: the browser's own (:focus-visible, :checked): write nothing
Its states are drawn from attributes and props, so assistive technology and your agent read the same thing:
| State | Drawn by |
|---|---|
| disabled | the attribute data-disabled |
Motion
- The part sets its own motion: add no transition or animation of your own.
- How the theme moves, and how to move your own parts the same way: Motion.
Notes for AI
Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.