Skip to content

Now in the official shadcn registry directory.

Start free

Collapsible

An unstyled single show/hide region on radix-ui, so it composes into any layout you build around it.

disclosure
A free styled version is available
3 environment variables

Installation

Run the following command

npx shadcn@latest add @ai2/collapsible

Dependencies, the @ai2/tokens theme and the component file are installed together.

Usage

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

<Collapsible>
  <CollapsibleTrigger>Toggle</CollapsibleTrigger>
  <CollapsibleContent>
    The content revealed when the region is open.
  </CollapsibleContent>
</Collapsible>

The component ships unstyled - wrap CollapsibleTrigger around your own control and put your layout inside CollapsibleContent.

Examples

Basic

3 environment variables

The demo drives open / onOpenChange from React state and supplies every class itself, since the component adds no styling of its own.

Props

Every part also forwards its underlying radix props. The region is unstyled, so it has no variant, tone or size axis.

PropTypeDefaultDescription
openboolean-Controlled open state of the region (on Collapsible). Pair with onOpenChange.
defaultOpenbooleanfalseOpen state when the region is uncontrolled (on Collapsible).
onOpenChange(open: boolean) => void-Called with the next open state when the region is toggled (on Collapsible).
disabledbooleanfalsePrevents the trigger from toggling the region (on Collapsible).
asChildbooleanfalseMerges props onto your own child element instead of rendering a button (on CollapsibleTrigger).

ai2 Collapsible: a single show and hide region for React

The ai2 Collapsible is a shadcn-compatible collapsible component for React, built on the radix-ui Collapsible primitive. It toggles one region of content open and closed from a trigger, and it ships intentionally unstyled so it composes into any layout you build around it, from a filter panel to a see-more block. You provide the wrapper, spacing and icon; the primitive handles the state, accessibility and data attributes.

Because it ships through the shadcn registry format, you install it with one CLI command, an MCP agent, or a copy-paste, and the source lands in your own project. You own the file; there is no runtime dependency on ai2 itself. The live example above is the exact component you get.

What is the ai2 Collapsible?

It is a three-part composition: Collapsible, CollapsibleTrigger and CollapsibleContent. The anatomy matches shadcn/ui exactly, so existing snippets, muscle memory and AI agents keep working without changes. The trigger forwards the radix asChild prop, so you can toggle the region from your own button or icon without an extra wrapper element.

Unlike Accordion, a Collapsible is a single region with no shared group state and no visual chrome of its own: there are no variants, tones or sizes to choose. Each part carries a data-slot and a data-state attribute of open or closed, so you decide the look entirely in your own Tailwind classes and drive any animation from those attributes.

Why use it

  • Accessible by construction: The radix-ui Collapsible primitive wires the trigger to the region with aria-expanded and aria-controls, and toggles it with keyboard and pointer, so screen readers announce the state.
  • Unstyled and composable: It ships with no chrome of its own, so it drops into any layout without fighting existing styles; you own every class on the wrapper, trigger and content.
  • Controlled or uncontrolled: Use defaultOpen for a self-managed region, or drive open and onOpenChange from React state when the toggle must sync with other UI.
  • State-driven styling: Every part exposes data-state="open" | "closed", so you can rotate a chevron or animate height purely from CSS without touching the component.
  • Agent-readable metadata: The registry item states that it is a single show/hide region and when to reach for Accordion instead, so an MCP agent installs the right primitive.

Features

  • shadcn registry install: One command adds the component, its dependencies and the @ai2/tokens theme to your project.
  • asChild trigger: CollapsibleTrigger forwards the radix asChild prop, so the toggle can be your own Button or icon button rather than a bare element.
  • Controlled state: The root forwards open, defaultOpen and onOpenChange, so the region can be self-managed or driven from your own React state.
  • Disabled state: Pass disabled to the root to lock the region open or closed, for example while a section is loading.
  • Data attributes for styling: Collapsible, its trigger and its content all expose data-slot and data-state, so you can restyle and animate the open and closed states from CSS alone.
  • Framework-agnostic source: The file imports only the radix Collapsible primitive, so the source you install has no ai2 or app-specific dependencies to carry along.

Production tips

  • Add your own animation: The region is unstyled and does not animate by default. Drive a height or opacity transition from the data-state attribute in your own CSS if you want motion.
  • Reach for Accordion for a set: A Collapsible is one independent region. When you have several sections that should behave as a group, or open one at a time, use Accordion instead.
  • Keep the trigger a real control: Use asChild on a focusable Button so keyboard users can toggle the region; a trigger on a plain div is not reachable for them.
  • Label an icon-only trigger: If the trigger is just a chevron, give it an aria-label like "Toggle" so assistive technology announces what it does.
  • Do not hide critical actions: Collapsed content is easy to miss, so keep anything a user must act on visible and reserve the region for secondary or supporting detail.

Works with the rest of ai2

A Collapsible pairs naturally with a ai2 Button as its trigger via asChild, and its content can hold any registry component, such as a stack of ai2 Badge chips or form fields.

When you need a set of grouped, mutually exclusive sections rather than a single region, reach for the ai2 Accordion, and for switching between peer views use ai2 Tabs. Everything shares one token source, so combinations stay visually consistent in both modes.

FAQs

Get new components in your inbox

Component drops, new themes and release notes. No spam, and you can unsubscribe from any email.

© 2026 ai2 design system · MIT licensed · Built with its own components