A single choice from a short list, drawn in one of five ways. Every variant is a group of native radio inputs: one tab stop, the arrow keys move the selection, and the value goes into FormData on its own. The selected look and the moving highlight of the segment variant are CSS through :has(:checked), so the component is a Server Component with no JavaScript.
Browser Support
Styles elements based on their contents
Colors indicators and selection bar
Preview
Switch the variant, the value stays the same.
Selected: Team
Installation
Usage
import { OptionPicker } from "@/components/ui/option-picker"
const plans = [
{ value: "starter", label: "Starter", description: "1 seat" },
{ value: "team", label: "Team", description: "Up to 10 seats" },
{ value: "studio", label: "Studio", description: "Unlimited" },
]
// A Server Component: the value lives in the radio inputs
export default function Example() {
return (
<form action="/checkout">
<OptionPicker
aria-label="Plan"
name="plan"
variant="segment"
options={plans}
defaultValue="team"
/>
</form>
)
}
// Inside a client component you can control it
<OptionPicker options={plans} value={plan} onValueChange={setPlan} />Examples
Icons and descriptions
Each option takes an icon and a short description. tiles shows them stacked, rows puts the description on the right.
const options = [
{ value: "walk", label: "On foot", description: "Under 2 km", icon: <Footprints /> },
{ value: "bike", label: "By bike", description: "2–10 km", icon: <Bike /> },
{ value: "train", label: "By train", description: "Any distance", icon: <TrainFront /> },
{ value: "car", label: "By car", description: "Any distance", icon: <Car /> },
]
<OptionPicker variant="tiles" options={options} defaultValue="bike" />
<OptionPicker variant="rows" options={options} defaultValue="train" />Scales
slider and bars suit ordered values where further means more. The slider stops are radio inputs too: click a stop or its caption, or use the arrow keys. Before the first pick it shows emptyLabel.
<OptionPicker variant="slider" options={levels} emptyLabel="Not selected" />
<OptionPicker variant="bars" options={levels} defaultValue="3" />Native forms
name is the name of the radio group, so the value goes into FormData without any script. The form below works with JavaScript turned off.
import { Button } from "@/components/ui/button"
<form action={savePlan}>
<OptionPicker name="plan" options={plans} defaultValue="starter" />
<Button type="submit">Submit</Button>
</form>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| options | OptionPickerOption[] | - | List of options |
| value | string | - | Selected value in controlled mode |
| defaultValue | string | - | Initial value in uncontrolled mode |
| onValueChange | (value: string) => void | - | Called with the new value. Only inside client components |
| variant | "segment" | "rows" | "tiles" | "slider" | "bars" | "segment" | How the choice is drawn |
| name | string | - | Name of the radio group for forms |
| disabled | boolean | false | Disable the whole group |
| required | boolean | - | The form is not sent until something is picked |
| emptyLabel | string | "Not selected" | Text of the slider before anything is picked |
| className | string | - | Additional CSS classes |
OptionPickerOption
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | Unique value |
| label | string | - | Visible text, also used as the accessible name |
| description | string | - | Secondary text |
| icon | ReactNode | - | Icon before the label |
| disabled | boolean | false | Option cannot be picked |