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" },
]}
/>
</>
);
}
Compose your own
These styled parts are included in the same install. Use children to build your layout; add className only when you want an override.
Scroll horizontally for long lines
import { RadioGroup, RadioGroupItem } from "@/components/jez-ui/ui/radio-group";Props & types
Scroll horizontally for long lines
React.ComponentProps<typeof P.Root> & {
options?: { label: React.ReactNode; 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 { RadioGroup as P } from "radix-ui";
import { cn } from "./utils";
export function RadioGroup({
options,
children,
className,
...props
}: React.ComponentProps<typeof P.Root> & {
options?: { label: React.ReactNode; value: string; disabled?: boolean }[];
}) {
return (
<P.Root className={cn("grid gap-3", className)} {...props}>
{options
? options.map((o) => (
<label key={o.value} className="flex items-center gap-3 text-sm">
<RadioGroupItem value={o.value} disabled={o.disabled} />
{o.label}
</label>
))
: children}
</P.Root>
);
}
export function RadioGroupItem({
className,
...props
}: React.ComponentProps<typeof P.Item>) {
return (
<P.Item
className={cn(
"flex size-5 shrink-0 items-center justify-center rounded-full border border-border bg-background outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:opacity-50",
className,
)}
{...props}
>
<P.Indicator className="size-2.5 rounded-full bg-primary" />
</P.Item>
);
}
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 →