npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-segmented-control.json --yesSegmented control
ProOne choice of two to five short options that applies at once — a view or a mode — drawn as touching segments in one pill, for React and Tailwind CSS. Part of Goop Pro.
What an agent sees
- SegmentedControlItemOne option of a SegmentedControl
- SegmentedControlIconA segment's 14 px pack glyph, in its words' ink, 6 px before them
import { SegmentedControl, SegmentedControlItem, SegmentedControlIcon } from '@/components/ui/goop/segmented-control';
import { Field } from '@/components/ui/goop/field';
<>
<SegmentedControl aria-label="View" fit defaultValue="week">
<SegmentedControlItem value="day">Day</SegmentedControlItem>
<SegmentedControlItem value="week">Week</SegmentedControlItem>
<SegmentedControlItem value="month">Month</SegmentedControlItem>
</SegmentedControl>
<Field orientation="vertical" label="Density" className="w-full">
<SegmentedControl size="lg" name="density" defaultValue="comfortable">
<SegmentedControlItem value="compact">Compact</SegmentedControlItem>
<SegmentedControlItem value="comfortable">Comfortable</SegmentedControlItem>
</SegmentedControl>
</Field>
<SegmentedControl aria-label="Status" fit defaultValue="open">
<SegmentedControlItem value="open" count={5}>Open</SegmentedControlItem>
<SegmentedControlItem value="done" count={0}>Done</SegmentedControlItem>
</SegmentedControl>
</>When to use
- One choice of two to five short options that applies at once — a view or a mode — drawn as touching segments in one pill.
- Use SegmentedControl for one of two to five short options that applies at once — a view or a mode; give it a label; it fills its column,
fitin a header or a toolbar. For panels under a row of tabs use Tabs; for a choice with descriptions, RadioGroup; for more options or long words, Select; for on and off, Switch. A status filter with counts: acounton each option, and acountLabelfor a screen reader. - Also called: segmented button.
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 Segmented control on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing. As a Pro part, its command comes from Goop's server once you sign in, with a one-time link that lasts ten minutes.
npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-segmented-control.json --yesAdd the Goop Segmented control to this project. The install steps are at https://goop.so/docs/install.mdUsage
import { SegmentedControl, SegmentedControlItem, SegmentedControlIcon } from '@/components/ui/goop/segmented-control';
import { Field } from '@/components/ui/goop/field';
<>
<SegmentedControl aria-label="View" fit defaultValue="week">
<SegmentedControlItem value="day">Day</SegmentedControlItem>
<SegmentedControlItem value="week">Week</SegmentedControlItem>
<SegmentedControlItem value="month">Month</SegmentedControlItem>
</SegmentedControl>
<Field orientation="vertical" label="Density" className="w-full">
<SegmentedControl size="lg" name="density" defaultValue="comfortable">
<SegmentedControlItem value="compact">Compact</SegmentedControlItem>
<SegmentedControlItem value="comfortable">Comfortable</SegmentedControlItem>
</SegmentedControl>
</Field>
<SegmentedControl aria-label="Status" fit defaultValue="open">
<SegmentedControlItem value="open" count={5}>Open</SegmentedControlItem>
<SegmentedControlItem value="done" count={0}>Done</SegmentedControlItem>
</SegmentedControl>
</>- Fits: schedule, flow, list, overview, states (their recipes).
- Also known as: SegmentedButton, ContentSwitcher, ViewSwitcher, ButtonToggle, PillSwitch.
- height, width, padding, gap, corner, text, motion: add no class for these.
API reference
| Option | Type | What it does |
|---|---|---|
| value? | string | The chosen option's value, for a control its caller holds (with onValueChange). |
| defaultValue? | string | The option chosen at first render; left out (and no value), the first option. |
| onValueChange? | (value: string) => void | Called with the option's value whenever a person chooses one. |
| name? | string | The native radios' name, sent with the form; a name of its own when left out, so two controls never share one. |
| size? | 'sm' | 'md' | 'lg' = 'md' | The pill's outer height: sm 24 px, md 28 px, lg 32 px — the control it sits beside. |
| fit? | boolean = false | As wide as its segments (a header's or a toolbar's control); left out, it fills its column in equal segments. |
| disabled? | boolean = false | Every option off: the pill dimmed once, no option takes the focus, a press or a key. |
- State: value (value / defaultValue / onValueChange); drawn by data-state=checked, data-disabled
| Part | What it is |
|---|---|
| SegmentedControlItem | One option of a SegmentedControl; its props: segmented-control--item.md |
| SegmentedControlIcon | A segment's 14 px pack glyph, in its words' ink, 6 px before them; decorative (the words or aria-label name it); icon: IconName — The pack's icon name |
- data-slot values (to select a part by): segmented-control, segmented-control-count, segmented-control-icon, segmented-control-indicator, segmented-control-item, segmented-control-label, segmented-control-radio, segmented-control-thumb
SegmentedControlItem
One option of a SegmentedControl.
import { SegmentedControlItem } from '@/components/ui/goop/segmented-control';Options
- value: string — The value the control reports, and sends with the form, when this option is chosen.
- disabled?: boolean — This option off: dimmed, skipped by the arrows, no press chooses it.
- aria-label?: string — The option's name when it holds only a glyph (
SegmentedControlIcon): required then. - count?: number — How many the option holds ("Open 5"), drawn after its words as a quiet number; 0 is drawn (an empty status says so), and an option with no
countdraws none. - countLabel?: (count: number) => string — The words a screen reader hears for the count after the option's name (
(n) => \${n} open\); the number by default.
Keyboard
| Key | What it does |
|---|---|
| Tab | Move to the chosen option, then out of the group |
| ArrowRight ArrowDown | Choose the next option, wrapping, skipping a disabled one |
| ArrowLeft ArrowUp | Choose the previous option, wrapping, skipping a disabled one |
| Space | Choose the focused option |
Accessibility
- The native element answers the keyboard.
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 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.