Skip to content
Components

Collapsible

Collapsible with thoughtful defaults, semantic styling, and editable source.

Open ↗

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/collapsible.json

Use it

Scroll horizontally for long lines
"use client";
import {Collapsible} from '@/components/jez-ui/ui/collapsible';
import {FileCode2} from 'lucide-react';

export default function Example(){

return <><div className="w-full max-w-md"><Collapsible title="Changed files · 3" defaultOpen>{["components/button.tsx","styles/theme.css","tests/controls.spec.ts"].map((file,i)=><div key={file} className="flex items-center gap-2 py-2 text-sm"><FileCode2 size={15} className="shrink-0 text-muted-foreground"/><span className="min-w-0 flex-1 truncate font-mono text-xs">{file}</span><span className="text-xs text-primary">+{[24,8,16][i]}</span></div>)}</Collapsible></div></>;
}

Props & types

Scroll horizontally for long lines
React.ComponentProps<typeof P.Root> & { title: string }

Source

View 2 source files

registry/ui/collapsible.tsx

Scroll horizontally for long lines
"use client";
import * as React from "react";
import { Collapsible as P } from "radix-ui";
import { ChevronDown } from "lucide-react";
import { cn } from "./utils";
export function Collapsible({
  title,
  children,
  className,
  ...props
}: React.ComponentProps<typeof P.Root> & { title: string }) {
  return (
    <P.Root
      className={cn(
        "w-full overflow-hidden rounded-lg border border-border",
        className,
      )}
      {...props}
    >
      <P.Trigger className="group flex w-full items-center justify-between gap-4 px-4 py-3.5 text-left text-sm font-medium hover:bg-muted/40">
        {title}
        <ChevronDown
          size={16}
          className="shrink-0 text-muted-foreground transition-transform duration-200 group-data-[state=open]:rotate-180"
        />
      </P.Trigger>
      <P.Content className="jez-collapse overflow-hidden">
        <div className="border-t border-border px-4 py-4 text-sm leading-relaxed text-muted-foreground">
          {children}
        </div>
      </P.Content>
    </P.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 · 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 →