Accordion

Sections that expand and collapse in place.

  • Composed
  • New in 0.1
import { Accordion, accordionPrimitive } from "nitro-ui-sdk/accordion";
HeroUI Native
Accordion
Expo UI
DisclosureGroupCollapsible
  • Accordion example screen, light appearance
    Light
  • Accordion example screen, dark appearance
    Dark
On this page

Accordion shows sections that expand and collapse in place: FAQ answers, order details, advanced settings. Each item has a trigger row with a chevron and a content region. The region’s height change animates natively, together with the items below it, and the chevron turns to point down while open.

Use Tabs when only one section should be visible at a time and switching is frequent, and ListGroup rows with a chevron when a section opens another screen.

Anatomy

import { Accordion } from "nitro-ui-sdk/accordion";

<Accordion.Root>
  <Accordion.Item itemKey="shipping">
    <Accordion.Trigger label="Shipping">
      <Accordion.Title>Shipping</Accordion.Title>
      <Accordion.Description>Arrives Friday</Accordion.Description>
      <Accordion.Indicator />
    </Accordion.Trigger>
    <Accordion.Content />
  </Accordion.Item>
</Accordion.Root>;
Part Description
Root Owns which items are expanded. Draws one card (surface), one card per item (splitted) or a plain list (default).
Item One section with a stable itemKey. Items after the first draw a hairline above them (except splitted).
Trigger The row that toggles its item: a button whose value says expanded or collapsed. A string child renders heading (title and description) and the indicator.
Title / Description The trigger’s text lines (heading part holds them).
Indicator The chevron. It turns 90 degrees while open, natively.
Content The body. It mounts on first expand and then stays mounted, so its state survives collapsing.

Usage

import { Accordion } from "nitro-ui-sdk/accordion";
import { Text } from "nitro-ui-sdk/text";

<Accordion.Root defaultValue={["shipping"]}>
  <Accordion.Item itemKey="shipping">
    <Accordion.Trigger>Shipping</Accordion.Trigger>
    <Accordion.Content>
      <Text color="muted">Two to four business days.</Text>
    </Accordion.Content>
  </Accordion.Item>
  <Accordion.Item itemKey="returns">
    <Accordion.Trigger>Returns</Accordion.Trigger>
    <Accordion.Content>
      <Text color="muted">Free within 30 days.</Text>
    </Accordion.Content>
  </Accordion.Item>
</Accordion.Root>;

Variants and sizes

Variant Look
default A plain list with hairlines, aligned with the page (no horizontal padding).
surface All items on one surface card with radius.card; dividers inset by spacing.lg.
splitted Each item on its own surface card, spacing.sm apart.

Sizes sm | md | lg (default md): trigger heights 44, 52, 60 pt; titles subheadline, headline, title3; chevron 12, 14, 16 pt. selectionMode is single (default: opening one item closes the other; the open one can be closed) or multiple.

import { Accordion } from "nitro-ui-sdk/accordion";
import { Text } from "nitro-ui-sdk/text";

<Accordion.Root variant="splitted" size="lg" selectionMode="multiple">
  <Accordion.Item itemKey="pickup">
    <Accordion.Trigger description="Today, 9:00">Pickup</Accordion.Trigger>
    <Accordion.Content>
      <Text>Gate 4, ask for the dock manager.</Text>
    </Accordion.Content>
  </Accordion.Item>
</Accordion.Root>;

States

  • Expanded / collapsed: the content region opens to its natural height and the chevron points down. Collapsed content is clipped, hidden from VoiceOver and from the agent.
  • Disabled: disabled on an item or on Root dims the trigger to opacity.disabled and refuses every toggle.
  • Pressed: the native Semantics highlight dims the trigger while the touch is down.
  • Reduced motion: the region and the chevron switch without animation.

Controlled

value/defaultValue/onValueChange over the keys of the expanded items (readonly string[]). details.preventDefault() declines a change; a controlled change reports requested until the owner re-renders.

import { useState } from "react";
import { Accordion, type AccordionValue } from "nitro-ui-sdk/accordion";

function Faq() {
  const [open, setOpen] = useState<AccordionValue>([]);
  return (
    <Accordion.Root selectionMode="multiple" value={open} onValueChange={(next) => setOpen(next)}>
      <Accordion.Item itemKey="billing">
        <Accordion.Trigger>Billing</Accordion.Trigger>
        <Accordion.Content>{null}</Accordion.Content>
      </Accordion.Item>
    </Accordion.Root>
  );
}

Props

Accordion.Root

Prop Type Default Description
selectionMode "single" | "multiple" "single" How many items can be open.
value readonly string[] Controlled expanded keys.
defaultValue readonly string[] [] Initial expanded keys.
onValueChange (value: AccordionValue, details: ActionDetails) => void Called before a change; preventDefault() declines.
disabled boolean false Disables every item.
variant "default" | "surface" | "splitted" "default" Look.
size "sm" | "md" | "lg" "md" Trigger height and type.
expandedLabel string "Expanded" VoiceOver value of an open trigger. Pass a localized string.
collapsedLabel string "Collapsed" VoiceOver value of a closed trigger. Pass a localized string.
label string The group’s agent name.
api Controller<AccordionActions> From accordionPrimitive.createApi().
agentId string Agent identity of the group.
styles AccordionStyles Per-part style resolvers.
layout LayoutStyleProps Layout of the root.

Accordion.Item

Prop Type Default Description
itemKey string Required. Key used in value, by the controller and by the agent.
disabled boolean false Refuses toggles of this item.
layout LayoutStyleProps Layout of the item.
part AccordionPart "item" Resolve another part’s style.

Accordion.Trigger

Prop Type Default Description
children string | ReactNode A string renders the default title and chevron. Custom content needs label.
label string the string child Spoken and agent name. Required with custom children.
description string Second line under the title; spoken after it.
hint string VoiceOver hint.
part AccordionPart "trigger" Resolve another part’s style.

Accordion.Content

Prop Type Default Description
children ReactNode The body.
layout LayoutStyleProps Merged over the content padding.
part AccordionPart "content" Resolve another part’s style.

Title and Description take children: string; Indicator takes only part.

Controller API

import { Accordion, accordionPrimitive } from "nitro-ui-sdk/accordion";

const api = accordionPrimitive.createApi();
<Accordion.Root api={api}>
  <Accordion.Item itemKey="shipping">
    <Accordion.Trigger>Shipping</Accordion.Trigger>
    <Accordion.Content />
  </Accordion.Item>
</Accordion.Root>;
api.current?.expand("shipping");
Action Signature Result
expand expand(key: string, source?: ActionSource): ChangeStatus accepted (also when already open), requested (controlled), refused, disabled or unavailable (no trigger with that key).
collapse collapse(key: string, source?: ActionSource): ChangeStatus Same results.
toggle toggle(key: string, source?: ActionSource): ChangeStatus Same results.

Styles

import { Accordion, type AccordionStyles } from "nitro-ui-sdk/accordion";

const styles: AccordionStyles = {
  title: ({ tokens, state }) => ({ text: { color: state.expanded ? tokens.colors.accent : tokens.colors.foreground } }),
  content: ({ tokens }) => ({ layout: { paddingBottom: tokens.spacing.xl } }),
};
<Accordion.Root styles={styles} />;

Parts: root, item, trigger, heading, title, description, indicator, content. Resolvers receive { tokens, variant, size, state } with state: { expanded: boolean; disabled: boolean; first: boolean } per item (the root resolves with expanded: false). Custom children opt in with useAccordionPart(props, "title") inside an Item.

Accessibility

  • Each trigger is a button named “title, description”, with the value expandedLabel or collapsedLabel, the hint and the disabled trait.
  • Collapsed content is hidden from VoiceOver while it stays mounted, so focus never lands in a clipped region.
  • Dividers and the chevron are decorative.

Agent API

Action Arguments Notes
toggle / expand / collapse none On each trigger: component AccordionItem, role button, value expanded or collapsed. Absent while disabled.
toggle / expand / collapse key: string On the group: component Accordion, role group, value = expanded keys joined with “, “, options = triggers. Waits for a controlled owner’s render and reports whether the item ended up as asked.

Controls inside collapsed content are not discoverable.

Platform notes

iOS Android
Expand and collapse Native KitCollapsible region (ios/layout/HybridNativeCollapsible.swift): it clips its content and, when expanded changes, solves the layout again inside UIView.animate, so the region and the items below move together with no JavaScript per frame. Skipped under Reduce Motion and inside recycled list cells. Verified in the iOS harness. HybridNativeCollapsible.kt runs a ChangeBounds transition on the root; written, compile-only on this machine.
Chevron view.animate rotation, instant under Reduce Motion. Same call.