Components

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.

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

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

Do
  • 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 defaultOpen when people usually need what’s inside.
  • Turn on hiddenUntilFound for long text, so the browser’s find-in-page can reach it and open the panel.
Don’t
  • 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>.

PropTypeDefault
defaultOpen
Starts open. For uncontrolled use.
booleanfalse
open
Whether the panel is open. For controlled use.
boolean—
onOpenChange
Called when the trigger opens or closes the panel.
(open: boolean, details) => void—
disabled
Ignores the trigger and dims it.
booleanfalse
render
Replaces the rendered element, e.g. render={<li />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

CollapsibleTrigger

The button that opens and closes the panel.

PropTypeDefault
variant
A muted label, a tinted group row, or no styles at all.
'subtle' | 'header' | 'bare''subtle'
chevron
Shows the caret. Never shown for bare.
booleantrue
nativeButton
Set to false when render swaps in something other than a <button>.
booleantrue
render
Replaces the rendered element, e.g. render={<li />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

CollapsiblePanel

The content that shows and hides. Renders a <div>.

PropTypeDefault
animated
Animates the height. Turn off where layout is measured right after a toggle.
booleantrue
hiddenUntilFound
Keeps a closed panel findable by find-in-page, which opens it.
booleanfalse
keepMounted
Keeps a closed panel in the DOM, hidden.
booleanfalse
render
Replaces the rendered element, e.g. render={<li />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—