Toggle Group
Toggle 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/toggle-group.jsonUse it
Scroll horizontally for long lines
"use client";
import {ToggleGroup} from '@/components/jez-ui/ui/toggle-group';
export default function Example(){
return <><ToggleGroup type="single" defaultValue="week" aria-label="Period" options={[{label:'Day',value:'day'},{label:'Week',value:'week'},{label:'Month',value:'month'}]}/></>;
}Props & types
Scroll horizontally for long lines
React.ComponentProps<typeof Primitive.Root> & {
options: { label: string; value: string }[];
}Source
View 2 source files
registry/ui/toggle-group.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
import { ToggleGroup as Primitive } from "radix-ui";
export function ToggleGroup({
options,
className,
...props
}: React.ComponentProps<typeof Primitive.Root> & {
options: { label: string; value: string }[];
}) {
return (
<Primitive.Root
className={cn(
"inline-flex rounded-xl border border-border p-1",
className,
)}
{...props}
>
{options.map((o) => (
<Primitive.Item
key={o.value}
value={o.value}
className="rounded-lg px-3 py-2 text-sm data-[state=on]:bg-muted"
>
{o.label}
</Primitive.Item>
))}
</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 →