Skip to content

Components / Accordion

Accordion

A square, monospaced set of disclosures. Let readers reveal related answers one at a time or keep several open, with Radix handling expansion, associations and keyboard navigation.

Storybook runs locally or as a separately hosted build; no hosted Storybook is configured. Source and setup links match the install revision.

Usage playground

Explore shipping and returns. Choose one or several open panels, require a single panel to stay open, or disable a question. Copy sample preserves the current configuration and open values.

Each kit includes the frame, mounting hardware and a printed assembly guide.

Open: product

Expansion mode
Single collapse
Availability
React / TSX
'use client';

import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from "@/components/ui/yads-accordion";

import { useState } from 'react';

Installation

pnpm dlx [email protected] add biehlio/yet-another-design-system/accordion#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40

Documentation samples use basic Tailwind utilities for layout. Install each YADS component imported by the sample.

Run this revision-pinned command in a shadcn-configured project. It installs yads-accordion, its scoped CSS, Radix Accordion and JetBrains Mono automatically. No Tailwind, global reset, theme provider or other YADS primitive is required.

Import the four parts from @/components/ui/yads-accordion and give each item a unique value. Every Copy sample button copies a complete React module, including its client boundary and any recipe CSS, even when collapsed. Examples use ordinary CSS and native actions so they also work without site styles.

Multiple panels and disabled items

Uncontrolled multiple mode uses an array of unique item values. Each panel toggles independently. Shipping is unavailable here; disabled triggers are skipped during keyboard navigation. Explain unavailable content rather than relying on opacity alone.

Each kit includes the frame, mounting hardware and a printed assembly guide.

Return unused kits within 30 days. Contact the workshop before sending your package.

React / TSX
'use client';

import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from "@/components/ui/yads-accordion";

const questions = [
  {

Keep one panel open

Single mode defaults to non-collapsible. Set defaultValue to start with one open panel. Its trigger cannot close it, but another enabled trigger can replace it. Without an initial value, all panels start closed until one is opened.

Each kit includes the frame, mounting hardware and a printed assembly guide.

React / TSX
'use client';

import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from "@/components/ui/yads-accordion";

const questions = [
  {

Controlled state and focus

Use value with onValueChange to own expansion. Opening a panel does not move focus into it. This explicit action opens shipping and focuses the forwarded trigger ref; Tab then reaches the link inside. Closed panels are removed from keyboard navigation.

Open: none

React / TSX
'use client';

import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from "@/components/ui/yads-accordion";

import { useRef, useState } from 'react';

className customization

Ordinary CSS and inline style pass through to each part. This copied recipe adds an edge without replacing theme colors or the focus ring. Content stays in normal flow; panel changes are immediate, and chevron motion is removed under reduced motion.

Each kit includes the frame, mounting hardware and a printed assembly guide.

React / TSX
'use client';

import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from "@/components/ui/yads-accordion";

const questions = [
  {

Accessibility

  • Use a meaningful outline. Each trigger is a button in a heading (h3 by default). Set headingLevel to match its surrounding section. Radix generates unique trigger/panel IDs, aria-expanded, aria-controls and labelled region relationships. Do not override those associations without maintaining both ends.
  • Keep the trigger name clear. Write the question as visible text and keep interactive controls inside the content, not inside the trigger. Disabled questions need a nearby explanation; disabled does not hide an already open panel.
  • Preserve keyboard access. Tab and Shift+Tab follow normal document order, including links in expanded panels. Enter and Space toggle a focused trigger. Vertical Up/Down move between enabled triggers and wrap; Home/End reach the first/last. Horizontal mode uses Left/Right and respects dir. Disabled triggers are skipped. Opening does not steal focus.
  • Do not hide essential actions. Closed panels are not keyboard reachable. Accordion is not a form control, does not submit values and does not implement tabs or nested-disclosure coordination. For a single independent disclosure, native details/summary may be sufficient.

Light is standalone by default; a containing .dark opts into dark colors. Both themes retain a visible 2px keyboard focus outline. Panels change immediately without height animation; the chevron transition is disabled for prefers-reduced-motion: reduce.

API reference

Import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from @/components/ui/yads-accordion. The matching exported types are AccordionProps, AccordionItemProps, AccordionTriggerProps and AccordionContentProps. Root props preserve Radix’s discriminated single/multiple union; Trigger adds headingLevel and omits asChild.

On narrow screens, focus the table and scroll horizontally to read all columns.

Accordion parts, props, types, defaults and behavior
PartPropTypeDefaultDescription
Accordiontype"single" | "multiple"RequiredSelects the value shape and expansion behavior. Root renders a div.
Accordionvalue / defaultValuestring (single) / string[] (multiple)Uncontrolled, all closedControlled current value or uncontrolled initial value. Use unique nonempty item values. Do not combine value with defaultValue or switch modes of ownership.
AccordiononValueChange(value: string) => void / (value: string[]) => voidNot setUpdate controlled values synchronously. A collapsed single value is an empty string; multiple uses an empty array.
Accordioncollapsibleboolean (single only)falseAllows the expanded single item to close. Multiple mode always permits closing individual panels. Non-collapsible does not open an initial panel automatically.
Accordion / AccordionItemdisabledbooleanfalseDisables every trigger or one item. Does not clear existing open values; expanded disabled content stays readable.
Accordionorientation / dir"vertical" | "horizontal" / "ltr" | "rtl""vertical" / inherited directionSelects arrow-key navigation, not a horizontal visual layout. Horizontal arrows respect direction.
AccordionItemvaluestringRequiredStable, unique identifier within this root. Item renders a div.
AccordionTriggerheadingLevel2 | 3 | 4 | 5 | 63Trigger owns a heading wrapping its button. Choose a level matching the page outline. Do not wrap it in another heading.
AccordionTriggerchildrenReactNodeNot setVisible accessible name. Use text or noninteractive inline content; never nest buttons or links inside the trigger.
AccordionContentforceMounttrueNot setKeeps closed content mounted for state retention. Scoped CSS still hides it from layout and accessibility; this is not an animation API. Content renders a region div with an inner padding div.
All partsclassName / style / refNative class, CSSProperties, React.RefNot setClasses are merged and native props/events forwarded. Root, Item and Content refs target HTMLDivElement; Trigger targets HTMLButtonElement, not the heading.
Root / Item / ContentasChildbooleanfalseRadix composition replaces the outer div; use a compatible element forwarding props/ref. Content applies padding directly to that child instead of adding an inner div. Trigger deliberately does not support asChild because it owns a heading, label and indicator. Ref types describe the default elements.

DOM props and state hooks

Native attributes such as id, title, aria-*, data-* and event handlers pass to the corresponding Radix element. Trigger uses a non-submitting button. Content supports links, controls and arbitrary React content. Use data-state="open"/"closed" and data-disabled for local CSS recipes. No global variables, utility function or theme provider is installed.

Playground defaults

Reset restores controlled single mode, collapsible enabled, all questions enabled, and product open. Switching expansion mode starts with product open. “Keep one open” supplies product when no value is selected; that is documentation behavior, not an automatic primitive default.