Collapsible
A trigger that shows and hides a panel, such as a sidebar section or a group of list rows. Built on ui-sdk’s Collapsible.
Usage
import {
Collapsible,
CollapsiblePanel,
CollapsibleTrigger,
} from 'nyctoui/collapsible'
<Collapsible defaultOpen>
<CollapsibleTrigger>Your teams</CollapsibleTrigger>
<CollapsiblePanel>…</CollapsiblePanel>
</Collapsible>The panel animates its height and clips its content while it does, so give the content its own padding where focus rings need room. Motion is skipped when the user prefers reduced motion.
Good for
- A section of a sidebar, like Projects or Favorites, that folds away.
- Advanced options under a simple form, such as proxy settings in a network dialog.
- A long stack trace or log under an error message in a developer tool.
- Replies folded under a comment in a discussion thread.
Anatomy
<Collapsible>
<CollapsibleTrigger />
<CollapsiblePanel />
</Collapsible>Examples
Subtle
The default trigger: a small, muted label with a caret after it, like a section label in the sidebar.
Header
variant="header" is a full-width tinted row with the caret first, like a group of issues in a list. Put a status icon or a count beside the label.
Custom trigger
variant="bare" draws nothing, so the trigger can be any control. Here it renders a Button below the panel.
Controlled
Pass open and onOpenChange to drive it from elsewhere.
Disabled
Found by page search
With hiddenUntilFound, a closed panel stays in the page, and the browser’s find-in-page opens it when a match is inside. Try searching for “inbox”.
Best practices
- Give the trigger words that say what’s inside, and add hidden text when a custom trigger is only an icon.
- Start it open with
defaultOpenwhen people usually need what’s inside. - Turn on
hiddenUntilFoundfor long text, so the browser’s find-in-page can reach it and open the panel.
- Hide what people need to finish a task. Folded content is easy to miss.
- Nest collapsibles more than two levels deep.
- Use several collapsibles for a set of sections that should open one at a time. That’s an accordion.
API reference
Collapsible
Groups a trigger and its panel. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
defaultOpenStarts open. For uncontrolled use. | boolean | false |
openWhether the panel is open. For controlled use. | boolean | — |
onOpenChangeCalled when the trigger opens or closes the panel. | (open: boolean, details) => void | — |
disabledIgnores the trigger and dims it. | boolean | false |
renderReplaces the rendered element, e.g. render={<li />}. | ReactElement | function | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
CollapsibleTrigger
The button that opens and closes the panel.
| Prop | Type | Default |
|---|---|---|
variantA muted label, a tinted group row, or no styles at all. | 'subtle' | 'header' | 'bare' | 'subtle' |
chevronShows the caret. Never shown for bare. | boolean | true |
nativeButtonSet to false when render swaps in something other than a <button>. | boolean | true |
renderReplaces the rendered element, e.g. render={<li />}. | ReactElement | function | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
CollapsiblePanel
The content that shows and hides. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
animatedAnimates the height. Turn off where layout is measured right after a toggle. | boolean | true |
hiddenUntilFoundKeeps a closed panel findable by find-in-page, which opens it. | boolean | false |
keepMountedKeeps a closed panel in the DOM, hidden. | boolean | false |
renderReplaces the rendered element, e.g. render={<li />}. | ReactElement | function | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |