Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Expandable for Astro

Open a panel in place and animate its contents with one of five effects.

Workshop agenda

Review the first sketches

Compare the two layouts

Choose the next steps

Installation

bunx --bun shadcn@latest add @gnostic/expandable

Usage

---
import { Expandable, ExpandableContent, ExpandableTrigger } from "@/components/ui/expandable"
---

<Expandable defaultOpen>
  <ExpandableTrigger>Meeting location</ExpandableTrigger>
  <ExpandableContent effect="fade">
    <p>Meet in the workshop on the first floor.</p>
  </ExpandableContent>
</Expandable>

Place the trigger first and the content second, both as direct children of Expandable. The parts render as details, summary, and div. The browser handles clicks, Enter, and Space. To control the panel from a script, set the native open property and listen for the toggle event on the root.

Motion

The panel animates to the height of its content. Set effect to fade, blur, slide-up, slide-down, or scale. Set stagger to show direct child elements in sequence. The delay is in seconds. Children exit together.

Use the Tailwind open: variant to change the width of the root. Use group-open/expandable: to style an element inside the trigger. Reduced motion skips the panel and content transitions. The disclosure works with JavaScript disabled. Browsers without CSS sibling-index() show the children together.

API Reference

PropType
defaultOpen?boolean

Render the panel open on first load.

Typeboolean
Defaultfalse
PropType
effect?ExpandableEffect

Effect to apply when the panel opens or closes.

TypeExpandableEffect
Default'fade'
stagger?boolean

Animate each direct child element in sequence when the panel opens.

Typeboolean
Defaultfalse
staggerDelay?number

Time in seconds between the start of each child effect.

Typenumber
Default0.04

View the registry source.