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.",
},
]}
/>
</>
);
}
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 { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from "@/components/jez-ui/ui/accordion";Props & types
Scroll horizontally for long lines
React.ComponentProps<typeof P.Root> & {
items?: { value: string; title: React.ReactNode; 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 { Accordion as P } from "radix-ui";
import { ChevronDown } from "lucide-react";
import { cn } from "./utils";
export function Accordion({
items,
children,
className,
...props
}: React.ComponentProps<typeof P.Root> & {
items?: { value: string; title: React.ReactNode; content: React.ReactNode }[];
}) {
return (
<P.Root className={cn("w-full", className)} {...props}>
{items
? items.map((i) => (
<AccordionItem key={i.value} value={i.value}>
<AccordionTrigger>{i.title}</AccordionTrigger>
<AccordionContent>{i.content}</AccordionContent>
</AccordionItem>
))
: children}
</P.Root>
);
}
export function AccordionItem({
className,
...props
}: React.ComponentProps<typeof P.Item>) {
return (
<P.Item className={cn("border-b border-border", className)} {...props} />
);
}
export function AccordionTrigger({
className,
children,
...props
}: React.ComponentProps<typeof P.Trigger>) {
return (
<P.Header>
<P.Trigger
className={cn(
"group flex w-full items-center justify-between gap-4 py-4 text-left text-sm font-medium outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:opacity-50",
className,
)}
{...props}
>
{children}
<ChevronDown
size={16}
aria-hidden
className="shrink-0 transition-transform group-data-[state=open]:rotate-180 motion-reduce:transition-none"
/>
</P.Trigger>
</P.Header>
);
}
export function AccordionContent({
className,
children,
...props
}: React.ComponentProps<typeof P.Content>) {
return (
<P.Content
style={
{
"--radix-collapsible-content-height":
"var(--radix-accordion-content-height)",
} as React.CSSProperties
}
className="jez-collapse overflow-hidden"
{...props}
>
<div
className={cn(
"pb-4 text-sm leading-relaxed text-muted-foreground",
className,
)}
>
{children}
</div>
</P.Content>
);
}
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 · lucide-react@0.577.0 · 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 →