Radio Group
FreeNewRadio buttons with a dot that eases in and out. One Tab stop for the whole group.
Installation
pnpm dlx shadcn@latest add @viewport/radio-group
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above.
"use client";
import { useId } from "react";
import { RadioGroup, RadioGroupItem } from "@/components/viewport/radio-group";
const options = [
{ value: "all", label: "Everything", hint: "Every reply, mention and status change." },
{ value: "mentions", label: "Mentions and assignments", hint: "Only when someone needs you." },
{ value: "none", label: "Nothing", hint: "You can still check the inbox yourself." },
];
export default function RadioGroupDemo() {
const id = useId();
return (
<div className="w-full max-w-sm rounded-2xl border border-border bg-card p-5">
<p id={`${id}-legend`} className="text-sm font-medium">
Email me about
</p>
<RadioGroup aria-labelledby={`${id}-legend`} defaultValue="mentions" className="mt-4 gap-4">
{options.map(({ value, label, hint }) => (
<div key={value} className="flex items-start gap-3">
<RadioGroupItem id={`${id}-${value}`} value={value} aria-describedby={`${id}-${value}-hint`} />
<div className="grid gap-0.5">
<label htmlFor={`${id}-${value}`} className="cursor-pointer text-sm font-medium leading-5">
{label}
</label>
<p id={`${id}-${value}-hint`} className="text-[13px] text-muted-foreground">
{hint}
</p>
</div>
</div>
))}
</RadioGroup>
</div>
);
}Accessibility
- Built on Radix Radio Group: arrow keys move and select.
- Each item pairs with a label and can be described by a hint.
- Respects prefers-reduced-motion.