Accordion Primitive
Accordion is a Starwind Runtime primitive in the controlled-value-group contract family. Astro and React share one semantic component API. React coordinates reactive state through controlled and default props plus callbacks. Astro renders initial state and coordinates later changes through DOM events and Runtime methods. Raw HTML uses Runtime attributes, DOM events, and imperative methods.
Anatomy
Use the Astro primitive adapter to render Accordion anatomy with the Runtime wiring included.
---import { Accordion } from "@starwind-ui/astro/accordion";---
<Accordion.Root> <Accordion.Item value="details"> <Accordion.Header> <Accordion.Trigger>Toggle details</Accordion.Trigger> </Accordion.Header> <Accordion.Panel>Accordion panel content</Accordion.Panel> </Accordion.Item></Accordion.Root>Use the React primitive adapter when Accordion state participates in React rendering.
import { Accordion } from "@starwind-ui/react/accordion";
export function Example() { return ( <Accordion.Root> <Accordion.Item value="details"> <Accordion.Header> <Accordion.Trigger>Toggle details</Accordion.Trigger> </Accordion.Header> <Accordion.Panel>Accordion panel content</Accordion.Panel> </Accordion.Item> </Accordion.Root> );}Render the Accordion data-sw-* contract yourself, then initialize createAccordion.
<div data-sw-accordion> <div data-sw-accordion-item data-value="details"> <h3 data-sw-accordion-header> <button data-sw-accordion-trigger type="button">Toggle details</button> </h3> <div data-sw-accordion-content role="region" hidden>Accordion panel content</div> </div></div>
<script type="module"> import { createAccordion } from "@starwind-ui/runtime/accordion";
const root = document.querySelector("[data-sw-accordion]"); if (root) { createAccordion(root); }</script>API Reference
Root
The main element that owns the Accordion Runtime instance.
- Default element
- div
- Discovery hook
- data-sw-accordion
- Role
- -
Props
value AccordionValue -
- Description
- Controls the current Accordion value.
- Kind
- control
- Targets
- root
- Full type
- AccordionValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
defaultValue AccordionValue -
- Description
- Sets the initial Accordion value for uncontrolled usage.
- Kind
- control
- Targets
- -
- Full type
- AccordionValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
type "single" | "multiple" "single"
- Description
- Sets the native type for the Root part.
- Kind
- option
- Targets
- -
- Full type
- "single" | "multiple"
collapsible boolean true
- Description
- Allows all Accordion items to be collapsed.
- Kind
- option
- Targets
- -
- Full type
- boolean
onValueChange (value: AccordionValue, details: AccordionValueChangeDetails) => void -
- Description
- Runs when the Accordion value changes.
- Kind
- callback
- Targets
- -
- Full type
- (value: AccordionValue, details: AccordionValueChangeDetails) => void
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
Events
valueChange onValueChange value: AccordionValue
- Description
- Fires when the value changes for Accordion.
- DOM event
- starwind:value-change
- Details type
- AccordionValueChangeDetails
- Timing
- before-state-commit
- Cancelable
- Yes
- Cancellation sequence
- Check internal eligibility and intent.
- Create one details object for the proposal.
- Call the Runtime callback with the details object when the controller exposes one.
- Dispatch the cancelable DOM event with the same details object, including when the callback canceled it.
- Read details.isCanceled, including cancellation caused by preventDefault().
- Apply the accepted state.
- Notify Runtime subscribers and other accepted-only observers.
State
value AccordionValue value / defaultValue
- Description
- Tracks the current Accordion value.
- Initial attribute
- data-default-value
- Runtime getter
- getValue
- Runtime setter
- setValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
Data Attributes
Runtime hooks
State
Metadata
Item
An interactive item inside the Accordion collection.
- Default element
- div
- Discovery hook
- data-sw-accordion-item
- Role
- -
Props
value string -
- Description
- Controls the current Accordion value.
- Kind
- option
- Targets
- item
- Full type
- string
- React
Use value for controlled state and defaultValue for default state, and onValueChange for change proposals.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
Use data-default-value for initial state, listen for starwind:value-change, and call setValue for later updates.
data-default-valuestarwind:value-changesetValue
disabled boolean false
- Description
- Disables the Item part.
- Kind
- option
- Targets
- item
- Full type
- boolean
Data Attributes
Runtime hooks
State
Metadata
Header
The header container for a Accordion item.
- Default element
- h3
- Discovery hook
- data-sw-accordion-header
- Role
- -
Data Attributes
Runtime hooks
Trigger
The control that opens, closes, or targets the Accordion content.
- Default element
- button
- Discovery hook
- data-sw-accordion-trigger
- Role
- -
Data Attributes
Runtime hooks
State
Panel
The content panel controlled by Accordion.
- Default element
- div
- Discovery hook
- data-sw-accordion-content
- Role
- region
Data Attributes
Runtime hooks
State
Runtime API
- Factory
createAccordion- Import
@starwind-ui/runtime/accordion- Root hook
- root
data-sw-accordion - Option props
- type, defaultValue, collapsible, value
Runtime Setters
Related Styled Components
Changelog
View version history v1.0.0 5 releases
v1.0.0
- Promoted this Primitive's vendoring version to the stable 1.0.0 baseline. Its existing API and Runtime behavior carry forward from the previous release.
v0.1.3
- Marked generated React Primitive files as client modules so vendored installs preserve client boundaries in React server frameworks.
- Kept generated React state-change callbacks and DOM events cancelable until the Runtime accepts the proposed state, then synchronized rendered state.
v0.1.2
- Made value-change proposals synchronously cancelable before uncontrolled state commits.
v0.1.1
- Made single-value accordions collapsible by default while preserving the option to require one item to remain open.
v0.1.0
- Introduced Runtime-managed single and multiple disclosure state, keyboard navigation, and panel presence.