Native Accordion for Astro
Group native HTML disclosures, choose an initially open answer, and style the summary and indicator.
Installation
bunx --bun shadcn@latest add @gnostic/native-accordionnpx shadcn@latest add @gnostic/native-accordionpnpm dlx shadcn@latest add @gnostic/native-accordionCopy the files
src/components/ui/native-accordion/index.tssrc/components/ui/native-accordion/native-accordion.astrosrc/components/ui/native-accordion/native-accordion-details.astrosrc/components/ui/native-accordion/native-accordion-summary.astrosrc/components/ui/native-accordion/native-accordion-content.astrosrc/components/ui/native-accordion/types.ts
Usage
---
import { NativeAccordion } from "@/components/ui/native-accordion"
---
<NativeAccordion
summary="Can I bring a guest?"
content="Yes. Add their name when you book."
open
/>
Each item renders a details element. Set the same name on related items to allow at most one open answer. Use a distinct name for each group on the page. Omit name to let readers open answers independently. Use open on the item that should start expanded.
Compose the parts
Use NativeAccordionDetails for the root. Put NativeAccordionSummary first and NativeAccordionContent after it. Each part accepts the HTML attributes for its element, including class. The summary supplies a chevron. Use its optional indicator slot to replace it.
NativeAccordion slots
summary?Astro content
Sets the visible label in the summary.
Astro contentsummary propindicator?Astro content
Replaces the decorative icon. This slot is also available on NativeAccordionSummary when composing the parts.
Astro contentChevron downTheme and layout
Set the border and radius on NativeAccordionDetails, the focus and label styles on NativeAccordionSummary, and the answer spacing on NativeAccordionContent. Templates can also target the native-accordion, native-accordion-summary, native-accordion-indicator, and native-accordion-content data slots.
Props
summary?string
Label on the summary. The summary slot can supply markup.
stringcontent?string
Text shown when open. The default slot can supply markup.
stringThe default slot on NativeAccordion replaces the content text.
Tab moves focus to the summary. Enter and Space toggle the answer with JavaScript disabled. The open and close animation respects the reader’s reduced-motion setting.