Back to Base UIYou are on Collapsible.

Collapsible

A single panel that opens from a separate trigger and closes its parent gap.

Available inAvailable in React, Vue, Svelte, Solid, JavaScript· All five frameworks

Libraries

Base UI

Motion

Spring + short tween

Reduced motion

Fade in place
collapsible.tsx
Play with the real component, then read the code it ships with.All components
01

Installation

Installing for React·components/prequelui/collapsible.tsx

Add the component

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/react/collapsible.json
npmthe default on every machine

First component? Set up your project first

Frameworks

The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.

5 runtimes
collapsible.tsx
"use client";

import * as React from "react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { ChevronDown } from "lucide-react";
import { cn } from "@/lib/utils";

export type CollapsibleProps = {
  open?: boolean;
  defaultOpen?: boolean;
  onOpenChange?: (open: boolean) => void;
  trigger?: React.ReactNode;
  children?: React.ReactNode;
  className?: string;
};

const resize = { duration: 0.45, ease: [0.4, 0, 0.1, 1] } as const;

export function Collapsible({
  open,
  defaultOpen = false,
  onOpenChange,
  trigger = "Show details",
  children,
  className,
}: CollapsibleProps) {
  const [internal, setInternal] = React.useState(defaultOpen);
  const value = open ?? internal;
  const reduce = useReducedMotion();
  const id = React.useId();

  const toggle = () => {
    const next = !value;
    if (open === undefined) setInternal(next);
    onOpenChange?.(next);
  };

  return (
    <div data-slot="collapsible" className={cn("w-full", className)}>
      <button
        type="button"
        aria-expanded={value}
        aria-controls={id}
        onClick={toggle}
        className="flex w-full items-center justify-between gap-4 py-3 text-left text-[13.5px] font-medium outline-none"
      >
        <span>{trigger}</span>
        <motion.span
          aria-hidden="true"
          animate={{ rotate: value ? 180 : 0 }}
          transition={resize}
          className="text-muted-foreground"
        >
          <ChevronDown className="size-4" />
        </motion.span>
      </button>
      <AnimatePresence initial={false}>
        {value && (
          <motion.div
            id={id}
            role="region"
            initial={reduce ? { opacity: 0 } : { height: 0, opacity: 0 }}
            animate={reduce ? { opacity: 1 } : { height: "auto", opacity: 1 }}
            exit={reduce ? { opacity: 0 } : { height: 0, opacity: 0 }}
            transition={reduce ? { duration: 0.2 } : resize}
            className="overflow-hidden"
          >
            <div className="pb-3 text-[13px] leading-6 text-muted-foreground">
              {children}
            </div>
          </motion.div>
        )}
      </AnimatePresence>
    </div>
  );
}

Install

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/react/collapsible.json
npmthe default on every machine

Dependencies

motion lucide-react

The registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.

02

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

collapsible.tsx
import { Collapsible } from "@/components/prequelui/collapsible";

export default function Demo() {
  return (
    <Collapsible>
      {/* compose the parts exactly like the underlying primitive */}
    </Collapsible>
  );
}
import { Collapsible } from "@/components/prequelui/collapsible";

export function Variant() {
  return (
    <Collapsible tempo={1.2}>
      …
    </Collapsible>
  );
}
03

Animation

This primitive keeps the API and semantics of the underlying component and adds motion at the surface edges. Entrances are slower and more settled than exits, so closing never feels like waiting.

  • Springs for position, scale and size; tweens for colour and opacity.
  • The exit is shorter than the entrance, and keeps the current position as its starting point.
  • All measurements are taken again when content or font metrics change.
  • With reduced motion, the surface fades in place and never travels.
spring 300 / 30exit 150 msblur 4 pxheight 450 ms
04

API Reference

Every part takes exactly the props of the Collapsible primitive. The animated surface adds only motion props, so the accessibility tree and keyboard behaviour stay the same.

Collapsible

PropTypeDefault
childrenReactNode—
disabledbooleanfalse
transitionTransitionspring.press
classNamestring—

Next component

Combobox

An input paired with a filtered list, gliding highlight and cascading rows.