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

Accordion for Astro

Build Astro accordions for FAQs and expandable content. Preview examples, install with shadcn, and read the keyboard and composition guide.

API Reference

Installation

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

Usage

import {
    Accordion,
    AccordionContent,
    AccordionItem,
    AccordionTrigger,
} from "@/components/ui/accordion"
<Accordion>
  <AccordionItem value="item-1">
    <AccordionTrigger>How do I open a question with the keyboard?</AccordionTrigger>
    <AccordionContent>
      Use Tab to reach the question, then Enter or Space to open its answer.
    </AccordionContent>
  </AccordionItem>
</Accordion>

Composition

Arrange the parts as shown for an Accordion:

Accordion
├── AccordionItem
│   ├── AccordionTrigger
│   └── AccordionContent
└── AccordionItem
    ├── AccordionTrigger
    └── AccordionContent

Examples

Multiple

Add multiple when readers need to compare answers without closing the previous item.

With Disabled

Set disabled on an AccordionItem when its trigger must be unavailable.

With Borders

For this divided layout, put border on the root and border-b last:border-b-0 on each item. The last item uses the root border as its lower edge.

In Card

Wrap the Accordion in a Card component.

FAQ

API Reference

AccordionProps

PropType
multiple?boolean

Allow multiple items open at once

Typeboolean
defaultValue?string | string[]

Initially expanded item(s)

Typestring | string[]
disabled?boolean

Disable the entire accordion

Typeboolean
orientation?AccordionOrientation

Accordion orientation for roving focus

TypeAccordionOrientation
loopFocus?boolean

Whether arrow-key focus wraps at the ends

Typeboolean
hiddenUntilFound?boolean

Use hidden="until-found" on closed panels

Typeboolean

See the data-slot docs for more information on interactivity.

AccordionTrigger slots

PropType
indicator?Astro content

Replaces the icon beside the trigger label.

TypeAstro content
DefaultChevron down

Events

Dispatch these events on the accordion root. The root emits the outbound events.

Outbound events

Event Detail
accordion:change { value: string[] }

Inbound events

Event Detail
accordion:set { value: string | string[] }

Read the installed source for the complete prop types.

When to use Accordion

Group related questions with Accordion items. Give each trigger a clear question or topic and place its answer in the matching content part. Keep the item structure from the examples so the controller can connect each trigger to its panel.

Keyboard and behavior

The data-slot controller handles trigger activation and expanded state. Use real trigger buttons so Enter and Space work. Keep essential instructions outside closed panels when the user needs them to complete a form. Test keyboard movement when items are disabled or added dynamically.

Theme and layout

Borders separate items and the indicator rotates with data-panel-open. Panel height uses the controller variable, so long content can animate without a fixed height. Theme changes affect text, focus, and borders. Do not apply a second height animation to the content wrapper.