Back to Shark UI

Collapsible

docs/components/collapsible

latest8.0 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

Collapsible

Copy Markdown

Collapsible content in a vertical stack.

DocsAPI

PreviewCode

Total visits

22.3%10.1%6.8%1.4%

Details

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/collapsible

Anatomy#

Collapsible
├── CollapsibleTrigger
└── CollapsibleContent

Usage#

import { 
  Collapsible, 
  CollapsibleTrigger, 
  CollapsibleContent 
} from "@/components/ui/collapsible";
<Collapsible>
  <CollapsibleTrigger>Can I use this in my project?</CollapsibleTrigger>
  <CollapsibleContent>
    Yes. Free to use for personal and commercial projects. No attribution
    required.
  </CollapsibleContent>
</Collapsible>

Controlled#

Use the open and onOpenChange props to control the collapsible state programmatically.

PreviewCode

Expand

States#

Disabled#

PreviewCode

Disabled Collapsible

Examples#

Nested#

Collapsibles can be nested to create hierarchical structures.

PreviewCode

Getting started

We'll help you get started

View details

Partial Collapse#

Use the collapsedHeight prop to show a portion of the content when collapsed.

PreviewCode

Read more

This is the first paragraph of content. When collapsed, only a portion of this content will be visible.

This is the second paragraph. It will be hidden when the collapsible is in its collapsed state.

This is the third paragraph. Expand the collapsible to see all the content.

This is the fourth paragraph. The collapsedHeight prop controls how much content is visible when collapsed.

Collapse (cannot be focused when collapsed)

Accessibility Notice

Interactive elements (links, buttons, inputs) within the collapsed area automatically become inaccesible to prevent keyboard navigation to hidden content.

API Reference#

Collapsible#

Root component. Controls expand/collapse state and animation.

PropTypeDefault
openboolean-
defaultOpenbooleanfalse
onOpenChange({ open }: OpenChangeDetails) => void-
collapsedHeightstring-
classNamestring-

CollapsibleTrigger#

Toggles expand/collapse on click. Use asChild for custom trigger elements.

PropTypeDefault
classNamestring-
asChildbooleanfalse

CollapsibleContent#

Holds the content that expands and collapses. Animated by default.

PropTypeDefault
classNamestring-
asChildbooleanfalse

CollapsibleIndicator#

Chevron or icon that rotates to indicate open/closed state.

PropTypeDefault
classNamestring-
asChildbooleanfalse

For a complete list of props, see the Ark UI documentation.

[

Previous page

Clipboard ](/docs/components/clipboard)[

Next page

Color Picker ](/docs/components/color-picker)

On This Page

InstallationAnatomyUsageControlledStatesDisabledExamplesNestedPartial CollapseAPI ReferenceCollapsibleCollapsibleTriggerCollapsibleContentCollapsibleIndicator