Skip to content

Collapsible

Layout

A controlled or uncontrolled disclosure for related content.

Controlled disclosureHidden and expanded content
Open preview

Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.

Usage

Wrap a trigger and content in Collapsible. Use asChild on the trigger with a single button child. Use Accordion for a collection of related disclosures.

Import
import {
  Collapsible,
  CollapsibleTrigger,
  CollapsibleContent,
} from "@/components/ui/collapsible";

Shipped as editable source in src/components/ui/collapsible.tsx in both apps. Copy the implementation below when moving it to another project. Copy the complete example from Source code for all imports and state. Add "use client" when using hooks or event handlers. See installation and theming for project setup.

Component source

The complete implementation is included in both apps. It uses the React, Radix, Lucide, and shared-core dependencies already installed in Apex. Keep your project’s semantic theme tokens when reusing it.

src/components/ui/collapsible.tsx
"use client";

import type { ComponentProps } from "react";
import { cn } from "@dashboardpack/core/lib/utils";

import { Collapsible as Primitive } from "radix-ui";
export const Collapsible = Primitive.Root;
export const CollapsibleTrigger = Primitive.Trigger;
export function CollapsibleContent({
  className,
  ...props
}: ComponentProps<typeof Primitive.Content>) {
  return (
    <Primitive.Content
      className={cn("space-y-2 text-sm data-[state=closed]:hidden", className)}
      {...props}
    />
  );
}

API reference

Common props and defaults. Slot-specific props are named below; native elements also accept their standard HTML attributes. The component TypeScript definitions are the complete type reference.

Collapsible props
PropType / DefaultDescription
open / defaultOpenboolean

Default: false

Controlled or initial visibility.
onOpenChange(open: boolean) => void

Default: —

Respond to disclosure changes.
disabledboolean

Default: false

Prevent interaction.
asChild (CollapsibleTrigger)boolean

Default: false

Use your own single trigger element.

Build with these too