Radio Group
Radio Group with thoughtful defaults, semantic styling, and editable source.
Make it yours.
Install the editable source and its dependencies into your React + Tailwind project.
Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/radio-group.jsonUse it
Scroll horizontally for long lines
"use client";
import {RadioGroup} from '@/components/jez-ui/ui/radio-group';
export default function Example(){
return <><RadioGroup defaultValue="balanced" aria-label="Density" options={[{label:'Comfortable',value:'comfortable'},{label:'Balanced',value:'balanced'},{label:'Compact',value:'compact'}]}/></>;
}Props & types
Scroll horizontally for long lines
React.ComponentProps<typeof Primitive.Root> & {
options: { label: string; value: string; disabled?: boolean }[];
}Source
View 2 source files
registry/ui/radio-group.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
import { RadioGroup as Primitive } from "radix-ui";
export function RadioGroup({
options,
className,
...props
}: React.ComponentProps<typeof Primitive.Root> & {
options: { label: string; value: string; disabled?: boolean }[];
}) {
return (
<Primitive.Root className={cn("grid gap-3", className)} {...props}>
{options.map((o) => (
<label key={o.value} className="flex items-center gap-3 text-sm">
<Primitive.Item
value={o.value}
disabled={o.disabled}
className="size-5 rounded-full border border-border flex items-center justify-center"
>
<Primitive.Indicator className="size-2.5 rounded-full bg-primary" />
</Primitive.Item>
{o.label}
</label>
))}
</Primitive.Root>
);
}
registry/ui/utils.ts
Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
return twMerge(clsx(values));
}
Dependencies
radix-ui@1.6.7 · clsx@2.1.1 · tailwind-merge@3.5.0
Accessibility & behaviour
Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.
Read the accessibility and performance guide →