Accordion
Astro is an web framework for building fast, scalable, and secure websites.
Astro provides a set of features that make it an ideal choice for building fast, scalable, and secure websites.
To get started with Astro, follow the instructions in the documentation.
---import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/starwind/accordion";---
<Accordion defaultValue="item-1"> <AccordionItem value="item-1"> <AccordionTrigger>What is Astro?</AccordionTrigger> <AccordionContent> Astro is an web framework for building fast, scalable, and secure websites. </AccordionContent> </AccordionItem> <AccordionItem value="item-2"> <AccordionTrigger>Why should I use Astro?</AccordionTrigger> <AccordionContent> Astro provides a set of features that make it an ideal choice for building fast, scalable, and secure websites. </AccordionContent> </AccordionItem> <AccordionItem value="item-3"> <AccordionTrigger>How do I get started with Astro?</AccordionTrigger> <AccordionContent> To get started with Astro, follow the instructions in the documentation. </AccordionContent> </AccordionItem></Accordion>import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/starwind/accordion";
export function Example() { return ( <Accordion defaultValue="item-1"> <AccordionItem value="item-1"> <AccordionTrigger>What is Astro?</AccordionTrigger> <AccordionContent> Astro is an web framework for building fast, scalable, and secure websites. </AccordionContent> </AccordionItem> <AccordionItem value="item-2"> <AccordionTrigger>Why should I use Astro?</AccordionTrigger> <AccordionContent> Astro provides a set of features that make it an ideal choice for building fast, scalable, and secure websites. </AccordionContent> </AccordionItem> <AccordionItem value="item-3"> <AccordionTrigger>How do I get started with Astro?</AccordionTrigger> <AccordionContent> To get started with Astro, follow the instructions in the documentation. </AccordionContent> </AccordionItem> </Accordion> );}Installation
pnpx starwind@latest add accordionnpx starwind@latest add accordionyarn dlx starwind@latest add accordionFramework Availability
Astro Available React AvailableAccordion is available for Astro and React.
Usage
multiple
Use type="multiple" to allow multiple accordion items to be open at the same time.
Astro is an web framework for building fast, scalable, and secure websites.
Astro provides a set of features that make it an ideal choice for building fast, scalable, and secure websites.
To get started with Astro, follow the instructions in the documentation.
---import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/starwind/accordion";---
<Accordion type="multiple" defaultValue={["item-1"]}> <AccordionItem value="item-1"> <AccordionTrigger>What is Astro?</AccordionTrigger> <AccordionContent> Astro is an web framework for building fast, scalable, and secure websites. </AccordionContent> </AccordionItem> <AccordionItem value="item-2"> <AccordionTrigger>Why should I use Astro?</AccordionTrigger> <AccordionContent> Astro provides a set of features that make it an ideal choice for building fast, scalable, and secure websites. </AccordionContent> </AccordionItem> <AccordionItem value="item-3"> <AccordionTrigger>How do I get started with Astro?</AccordionTrigger> <AccordionContent> To get started with Astro, follow the instructions in the documentation. </AccordionContent> </AccordionItem></Accordion>Runtime example adjustment
Multiple accordions use an array for defaultValue because the Runtime may own more than one open item.
defaultValue
Use the defaultValue prop to set the default open item. If the prop is not provided, no items will be open by default.
Astro is an web framework for building fast, scalable, and secure websites.
Astro provides a set of features that make it an ideal choice for building fast, scalable, and secure websites.
To get started with Astro, follow the instructions in the documentation.
---import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/starwind/accordion";---
<Accordion defaultValue="item-3"> <AccordionItem value="item-1"> <AccordionTrigger>What is Astro?</AccordionTrigger> <AccordionContent> Astro is an web framework for building fast, scalable, and secure websites. </AccordionContent> </AccordionItem> <AccordionItem value="item-2"> <AccordionTrigger>Why should I use Astro?</AccordionTrigger> <AccordionContent> Astro provides a set of features that make it an ideal choice for building fast, scalable, and secure websites. </AccordionContent> </AccordionItem> <AccordionItem value="item-3"> <AccordionTrigger>How do I get started with Astro?</AccordionTrigger> <AccordionContent> To get started with Astro, follow the instructions in the documentation. </AccordionContent> </AccordionItem></Accordion>API Reference
Styled Component API
These props are added or materially changed by the installed Astro styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Follow the Primitive and Runtime links for lower-level behavior props.
Accordion
Inherits div attributes.
Contains the following additional props:
defaultValue string | string[] —
- Description
- Sets the initial value when the component is uncontrolled.
- Classification
- Primitive override
- Primitive prop
- accordion.Root.defaultValue
Accordion Item
Inherits div attributes.
Contains the following additional props:
value Required string —
- Description
- Controls or identifies the component value.
- Classification
- Wrapper prop
Primitive And Runtime API
Use these references when you need the lower-level behavior APIs behind Accordion.
Primitive API
Runtime API
- Accordion primitive
createAccordionfrom@starwind-ui/runtime/accordion
Changelog
v2.0.1
- Single accordions now default to collapsible.
v2.0.0
- Rebuilt Accordion on Starwind Runtime for disclosure state and keyboard behavior;
- See the Accordion Primitive for the underlying unstyled anatomy and behavior API.
v1.3.5
- Refactor tailwind variants functions into separate
variants.tsfile
v1.3.3
- Add
starwind:initevent listener to enable initialization of additional Accordions loaded after an initial page load, such as when using server islands - Update the opening animation so that it does not play on initial accordion load
v1.3.2
- add named slot “icon” to
AccordionTriggerto enable easy icon swapping
v1.3.1
- simplified default styling to enable easier custom styling
v1.3.0
- style and focus state updates
v1.2.0
- Add a
data-slotattribute to all components to enable global styling updates
v1.1.0
tailwind-variantsnow implemented. This usestailwind-mergeunder the hood to merge Tailwind classes without style conflicts, allowing you to override any existing classes using theclassprop.