Accordion
Accordion 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/accordion.jsonUse it
Scroll horizontally for long lines
"use client";
import {Accordion} from '@/components/jez-ui/ui/accordion';
export default function Example(){
return <><Accordion type="single" collapsible items={[{value:'one',title:'What makes a good component?',content:'A clear purpose, thoughtful defaults, and room to make it yours.'},{value:'two',title:'Can I change it?',content:'The source is yours to adapt under your distribution licence.'}]}/></>;
}Props & types
Scroll horizontally for long lines
React.ComponentProps<typeof Primitive.Root> & {
items: { value: string; title: string; content: React.ReactNode }[];
}Source
View 2 source files
registry/ui/accordion.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
import { Accordion as Primitive } from "radix-ui";
export function Accordion({
items,
className,
...props
}: React.ComponentProps<typeof Primitive.Root> & {
items: { value: string; title: string; content: React.ReactNode }[];
}) {
return (
<Primitive.Root className={cn("w-full", className)} {...props}>
{items.map((i) => (
<Primitive.Item
key={i.value}
value={i.value}
className="border-b border-border"
>
<Primitive.Header>
<Primitive.Trigger className="flex w-full justify-between gap-4 py-4 text-left font-medium">
{i.title}
<span aria-hidden="true">+</span>
</Primitive.Trigger>
</Primitive.Header>
<Primitive.Content className="pb-4 text-sm text-muted-foreground">
{i.content}
</Primitive.Content>
</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 →