Skip to main content

Starwind UI v3.0 is now available! Migration guide

Installation

Usage

---
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>

Composition

Use this structure for an accordion with one or more items:

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

Multiple Items

Use type="multiple" to allow multiple accordion items to be open at the same time.

Open by Default

Use the defaultValue prop to set the default open item. If the prop is not provided, no items will be open by default.

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Accordion

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
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:

Prop Type Default Toggle details
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
createAccordion from @starwind-ui/runtime/accordion

Changelog

View version history v2.1.0 13 releases

v2.1.0

  • In Svelte, a defined value that you pass when Accordion mounts now stays under your control, as in React and Vue. To change it, use bind: or update your state in the change callback. A form reset keeps it. If you pass undefined at mount, Accordion keeps its own state.
  • In Svelte, Accordion now follows push() and splice() on a $state array that you pass as value.

v2.0.4

  • Vue Accordion keeps its previous expanded items when an open or close action is canceled.

v2.0.3

  • The default export in index.ts now has a name, AccordionParts, so framework tools show a clear name.

v2.0.2

  • In Astro and React, the last Accordion item no longer has a divider border.

v2.0.1

  • Single accordions now default to collapsible.

v2.0.0

  • Accordion now gets its behavior from Starwind Runtime. Runtime opens and closes the items and handles the keyboard.
  • See the Accordion Primitive for the unstyled parts and the behavior API.

v1.3.5

  • The Tailwind variants now live in their own variants.ts file in the component folder.

v1.3.3

  • Add starwind:init event 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 AccordionTrigger to 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-slot attribute to all components to enable global styling updates

v1.1.0

  • tailwind-variants now implemented. This uses tailwind-merge under the hood to merge Tailwind classes without style conflicts, allowing you to override any existing classes using the class prop.