Skip to main content

Accordion

A vertically stacked set of headers that each reveal a section of content.

Installation

npm install @sipe-team/accordion
import '@sipe-team/accordion/styles.css';

Usage

Examples

Multiple (default)

Independent items — any number open at once, no value needed.

Single

Mutually exclusive — each item needs a value.

Initially open

initialValue opens an item in single mode; defaultOpen does the same per-item in multiple mode.

Open on first render.

asChild

Root, Trigger, and Content merge their props onto the child instead of rendering a div / button / div. With asChild on Trigger, pass a genuinely focusable element — the default type="button" is not applied.

Anatomy

import { Accordion } from '@sipe-team/accordion';

export default () => (
<Accordion.Root>
<Accordion.Item>
<Accordion.Trigger>
{/* header label */}
<Accordion.Indicator />
</Accordion.Trigger>
<Accordion.Content>{/* panel content */}</Accordion.Content>
</Accordion.Item>
</Accordion.Root>
);

Accordion and Accordion.Root are the same component. Parts are also exported standalone (AccordionRoot, AccordionItem, …). Trigger, Content, and Indicator read state from context and throw outside their parent.

API Reference

Accordion.Root

div, forwards ref.

PropTypeDefaultDescription
childrenReactNodeRequired.
type'single' | 'multiple''multiple''single' makes items with a value exclusive.
initialValuestring | nullnullUncontrolled initial selection (single mode).
valuestring | nullControlled selection (single mode).
onValueChange(value: string | null) => voidFires with the new value, or null when toggled shut.
asChildbooleanfalseMerge props onto the child instead of a div.
classNamestringAppended to the component's class.

Also accepts ComponentProps<'div'>. In multiple mode the root holds no state — initialValue, value, and onValueChange are ignored, and each item uses its own defaultOpen.

Accordion.Item

div, forwards ref. Does not extend ComponentProps.

PropTypeDefaultDescription
childrenReactNodeRequired. Usually a Trigger and a Content.
valuestringRequired in single mode; unused otherwise.
defaultOpenbooleanfalseInitial open state. Ignored in single mode.
classNamestringAppended to the component's class.

Accordion.Trigger

<button type="button">, forwards ref. Sets aria-expanded.

PropTypeDefaultDescription
childrenReactNodeRequired. Header label, usually with Indicator.
asChildbooleanfalseMerge props onto the child instead of a button.
classNamestringAppended to the component's class.

Also accepts ComponentProps<'button'>.

Accordion.Indicator

No props. Renders the arrow icon and rotates it with the item's open state.

Accordion.Content

Height-animated wrapper (aria-hidden) around an inner element. Does not forward a ref.

PropTypeDefaultDescription
childrenReactNodeRequired. Panel content.
asChildbooleanfalseMerge props onto the child instead of a div.
classNamestringApplied to the inner element, not the wrapper.