Expandable for Astro
Open a panel in place and animate its contents with one of five effects.
Installation
bunx --bun shadcn@latest add @gnostic/expandablenpx shadcn@latest add @gnostic/expandablepnpm dlx shadcn@latest add @gnostic/expandableCopy the files
src/components/ui/expandable/expandable-content.astrosrc/components/ui/expandable/expandable-trigger.astrosrc/components/ui/expandable/expandable.astrosrc/components/ui/expandable/index.tssrc/components/ui/expandable/types.ts
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
defaultOpen?boolean
Render the panel open on first load.
booleanfalseeffect?ExpandableEffect
Effect to apply when the panel opens or closes.
ExpandableEffect'fade'stagger?boolean
Animate each direct child element in sequence when the panel opens.
booleanfalsestaggerDelay?number
Time in seconds between the start of each child effect.
number0.04