npx shadcn@4.23.1 add @goop/meadow-radio-groupRadio group
FreeA named group of options of which exactly one is chosen, each option a whole row a press anywhere on chooses, for React and Tailwind CSS. Free, MIT.
What an agent sees
- RadioGroupItemOne option's radio, inside a RadioGroupLabel with its words
- RadioGroupLabelOne option's row
- RadioGroupDescriptionAn option's short description
- RadioGroupContentA stacked option's words
- RadioGroupMediaAn option's picture, last in its RadioGroupLabel
import {
RadioGroup,
RadioGroupContent,
RadioGroupDescription,
RadioGroupItem,
RadioGroupLabel,
RadioGroupMedia,
} from '@/components/ui/goop/radio-group';
function DefaultNoteView({ view, onView }: { view: string; onView: (next: string) => void }) {
return (
<div className="flex flex-col gap-2">
<h3 id="note-view" className="text-base font-medium">
Open new Fieldwork notes as
</h3>
<RadioGroup aria-labelledby="note-view" name="note-view" value={view} onValueChange={onView}>
<RadioGroupLabel>
<RadioGroupItem value="page" />A full page
<RadioGroupDescription>The note fills the window, its list folded away.</RadioGroupDescription>
</RadioGroupLabel>
<RadioGroupLabel>
<RadioGroupItem value="side" />A side panel
<RadioGroupDescription>The note opens beside the list, which stays in view.</RadioGroupDescription>
</RadioGroupLabel>
</RadioGroup>
</div>
);
}
function VisitLogStart() {
return (
<RadioGroup aria-label="Start the visit log" name="log-start" defaultValue="open">
<RadioGroupLabel>
<RadioGroupItem value="arrive" />
<RadioGroupContent>
When I arrive
<RadioGroupDescription>The visit log starts as you reach the site</RadioGroupDescription>
</RadioGroupContent>
</RadioGroupLabel>
<RadioGroupLabel>
<RadioGroupItem value="open" />
<RadioGroupContent>
When I open the visit
<RadioGroupDescription>The log starts once you open the visit on your phone</RadioGroupDescription>
</RadioGroupContent>
<RadioGroupMedia>
<img src="/fieldwork/visit-tile.png" alt="" />
</RadioGroupMedia>
</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, each option a whole row a press anywhere on chooses.
- Also called: radio buttons.
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/meadow-radio-groupAdd the Goop Radio group to this project. The install steps are at https://goop.so/docs/install.mdUsage
import {
RadioGroup,
RadioGroupContent,
RadioGroupDescription,
RadioGroupItem,
RadioGroupLabel,
RadioGroupMedia,
} from '@/components/ui/goop/radio-group';
function DefaultNoteView({ view, onView }: { view: string; onView: (next: string) => void }) {
return (
<div className="flex flex-col gap-2">
<h3 id="note-view" className="text-base font-medium">
Open new Fieldwork notes as
</h3>
<RadioGroup aria-labelledby="note-view" name="note-view" value={view} onValueChange={onView}>
<RadioGroupLabel>
<RadioGroupItem value="page" />A full page
<RadioGroupDescription>The note fills the window, its list folded away.</RadioGroupDescription>
</RadioGroupLabel>
<RadioGroupLabel>
<RadioGroupItem value="side" />A side panel
<RadioGroupDescription>The note opens beside the list, which stays in view.</RadioGroupDescription>
</RadioGroupLabel>
</RadioGroup>
</div>
);
}
function VisitLogStart() {
return (
<RadioGroup aria-label="Start the visit log" name="log-start" defaultValue="open">
<RadioGroupLabel>
<RadioGroupItem value="arrive" />
<RadioGroupContent>
When I arrive
<RadioGroupDescription>The visit log starts as you reach the site</RadioGroupDescription>
</RadioGroupContent>
</RadioGroupLabel>
<RadioGroupLabel>
<RadioGroupItem value="open" />
<RadioGroupContent>
When I open the visit
<RadioGroupDescription>The log starts once you open the visit on your phone</RadioGroupDescription>
</RadioGroupContent>
<RadioGroupMedia>
<img src="/fieldwork/visit-tile.png" alt="" />
</RadioGroupMedia>
</RadioGroupLabel>
</RadioGroup>
);
}- Fits: flow (its recipe).
- 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 native group's name, sent with the form; a name of its own when left out, so two groups never share one. |
| 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 (vertical, the default) or rows side by side that wrap (horizontal). |
- State: value (value / defaultValue / onValueChange); drawn by data-state=checked
| 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 with the form, when this option is chosen; also takes onChange?: (event: ChangeEvent<HTMLInputElement>) => void; required?: boolean; disabled?: boolean; form?: string |
| RadioGroupLabel | One option's row; put its RadioGroupItem in it first, then the option's words, then an optional RadioGroupDescription; also takes htmlFor?: string |
| RadioGroupDescription | An option's short description |
| RadioGroupContent | A stacked option's words |
| RadioGroupMedia | An option's picture, last in its RadioGroupLabel |
Keyboard
| Key | What it does |
|---|---|
| ArrowUp ArrowDown ArrowLeft ArrowRight | Move selection |
| Space | Choose focused |
Accessibility
- The native element answers the keyboard.
- hover, focus-visible: the browser's own (:hover, :focus-visible): write nothing
Its states are drawn from attributes and props, so assistive technology and your agent read the same thing:
| State | Drawn by |
|---|---|
| checked | the attribute data-state=checked |
| disabled | the prop disabled |
| invalid | the attribute aria-invalid |
Motion
- The part sets its own motion: add no transition or animation of your own.
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.