GooseUI

Components

Collapsible

New

Collapsible shows and hides a block of content when its trigger is clicked. Keep the state inside with defaultOpen or control it from outside with open and onOpenChange. Height animates through interpolate-size, and the closed panel gets hidden="until-found", so in-page search opens it on its own. The trigger accepts asChild and sets aria-expanded and aria-controls for you.

Browser support

interpolate-size

Lets height animate between zero and auto.

Your browser:
hidden="until-found"

The closed panel is found by in-page search and opens itself.

Your browser:

Preview

Hidden content

Installation

npx shadcn@latest add @gooseui/collapsible
pnpm dlx shadcn@latest add @gooseui/collapsible
yarn dlx shadcn@latest add @gooseui/collapsible
bunx --bun shadcn@latest add @gooseui/collapsible

Usage

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

<Collapsible>
  <CollapsibleTrigger>Toggle</CollapsibleTrigger>
  <CollapsibleContent>Hidden content</CollapsibleContent>
</Collapsible>

Examples

Basic

Hidden content

<Collapsible>
  <CollapsibleTrigger asChild>
    <Button variant="outline">Toggle</Button>
  </CollapsibleTrigger>
  <CollapsibleContent>Hidden content</CollapsibleContent>
</Collapsible>

Open by default

Hidden content

<Collapsible defaultOpen>
  <CollapsibleTrigger asChild>
    <Button variant="outline">Toggle</Button>
  </CollapsibleTrigger>
  <CollapsibleContent>Hidden content</CollapsibleContent>
</Collapsible>

Controlled

Closed

Hidden content

const [open, setOpen] = React.useState(false)

<Collapsible open={open} onOpenChange={setOpen}>
  <CollapsibleTrigger asChild>
    <Button variant="outline">Toggle</Button>
  </CollapsibleTrigger>
  <CollapsibleContent>Hidden content</CollapsibleContent>
</Collapsible>

Props

PropTypeDefaultDescription
openboolean-Controlled state. Together with onOpenChange it makes the component controlled.
defaultOpenbooleanfalseInitial state in uncontrolled mode.
onOpenChange(open: boolean) => void-Called when the state changes.
asChildbooleanfalseCollapsible and CollapsibleTrigger: pass the props to the single child element instead of rendering a wrapper.
classNamestring-Additional CSS classes for Collapsible, CollapsibleTrigger and CollapsibleContent.