Radio group
ProA set of choices where one can be picked. Arrow keys move between them. Leave value empty (or pass "") so nothing is chosen until the person chooses.
Preview
Install
With the Candor CLI
First time? Get started sets up the registry and theme. Or with shadcn directly: npx shadcn@latest add @candor/radio-group
Brings in: render-prop, utils · npm: lucide-react@^1.67.0, radix-ui@^1.8.1
Usage
"use client"
import * as React from "react"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
const choices = [
{ value: "approve", label: "Approve and send as written", detail: "The customer gets this reply with its sources." },
{ value: "edit", label: "Edit, then send", detail: "Counts as a fail, with your reason." },
{ value: "reject", label: "Reject: send nothing", detail: "Nothing reaches the customer." },
]
export default function Example() {
// Nothing is chosen until the person chooses.
const [decision, setDecision] = React.useState("")
return (
<RadioGroup aria-label="Your decision" value={decision} onValueChange={setDecision} className="w-full max-w-sm">
{choices.map((c) => (
<label key={c.value} className="flex cursor-pointer items-start gap-2.5 rounded-lg border px-3 py-2 text-sm has-[[data-state=checked]]:border-ring has-[[data-state=checked]]:bg-accent/60">
<RadioGroupItem value={c.value} className="mt-0.5" />
<span>
<span className="font-medium">{c.label}</span>
<span className="block text-xs text-muted-foreground">{c.detail}</span>
</span>
</label>
))}
</RadioGroup>
)
}<RadioGroup>
No props.
Also takes the props of React.ComponentProps<typeof RadioGroupPrimitive.Root>RenderProp.
<RadioGroupItem>
One choice. Pair it with a label: wrap both in a <label>, or give it an id and the label htmlFor.
No props.
Also takes the props of React.ComponentProps<typeof RadioGroupPrimitive.Item>RenderProp.