Collapsible
A panel that can be toggled open or closed.
Import
import { Collapsible } from '@matix/components/collapsible';Usage
Default Open
Set defaultOpen to render the panel expanded on mount.
<Collapsible.Root defaultOpen>
<Collapsible.Trigger>Collapse details</Collapsible.Trigger>
<Collapsible.Panel>This content is visible by default.</Collapsible.Panel>
</Collapsible.Root>Trigger as a Button
Pass render to draw the trigger as another element. The trigger then drops its own text-button look, so the Button keeps its variant and size.
<Collapsible.Root>
<Collapsible.Trigger render={<Button variant="outline" size="sm" />}>
Toggle details
</Collapsible.Trigger>
<Collapsible.Panel>Here is some content that can be shown or hidden.</Collapsible.Panel>
</Collapsible.Root>Controlled
Use open and onOpenChange for controlled state.
import { useState } from 'react';
function ControlledCollapsible() {
const [open, setOpen] = useState(false);
return (
<div>
<Collapsible.Root open={open} onOpenChange={setOpen}>
<Collapsible.Trigger>{open ? 'Hide' : 'Show'} content</Collapsible.Trigger>
<Collapsible.Panel>Controlled collapsible content.</Collapsible.Panel>
</Collapsible.Root>
<span>Open: {String(open)}</span>
</div>
);
}Animation
Panel expand/collapse animations are enabled automatically when MatixProvider has animations turned on (the default). Animations respect prefers-reduced-motion.
Custom Styles
Use the sx prop on any sub-component to override styles.
import * as stylex from '@stylexjs/stylex';
const custom = stylex.create({
trigger: { fontWeight: 600, color: '#0f172a' },
panel: { padding: '12px 0', color: '#64748b', fontSize: 14 },
});
<Collapsible.Root>
<Collapsible.Trigger sx={custom.trigger}>Styled trigger</Collapsible.Trigger>
<Collapsible.Panel sx={custom.panel}>Styled panel content with muted text.</Collapsible.Panel>
</Collapsible.Root>;Server Components
Collapsible is a client component. A Server Component cannot read a property of a client component, so Collapsible.Root is undefined there. In a Server Component, import the named parts. Each Collapsible.<Part> is also exported as Collapsible<Part>.
import {
CollapsibleRoot,
CollapsibleTrigger,
CollapsiblePanel,
} from '@matix/components/collapsible';In a client component, both forms work.
API Reference
| Component | Prop | Type | Default | Description |
|---|---|---|---|---|
Collapsible.Root | defaultOpen | boolean | false | Whether the panel is open initially (uncontrolled) |
Collapsible.Root | open | boolean | — | Open state (controlled) |
Collapsible.Root | onOpenChange | (open: boolean) => void | — | Called when the open state changes |
Collapsible.Root | disabled | boolean | false | Disables the collapsible |
Collapsible.Root | sx | StyleXStyles | — | StyleX style override |
Collapsible.Trigger | sx | StyleXStyles | — | StyleX style override |
Collapsible.Panel | sx | StyleXStyles | — | StyleX style override |
All other props on each sub-component are forwarded to the underlying Base UI element.
Accessibility
- Built on Base UI
Collapsible— implements WAI-ARIA disclosure pattern. - The trigger has
aria-expandedreflecting the current state andaria-controlspointing to the panel. - Disabled state sets
aria-disabledand blocks interaction. - Focus ring is visible on keyboard navigation only (
:focus-visible).
Keyboard
| Key | Action |
|---|---|
Enter | Toggles the panel open or closed |
Space | Toggles the panel open or closed |