Accordion Component

The Accordion component is a flexible UI primitive built with React and TypeScript. It allows users to expand and collapse content sections, making it ideal for FAQs, documentation, and content-heavy interfaces.

It supports single or multiple open sections via allowMultiple, controlled default state using defaultOpen, and customization hooks for the item, header, title, icon, content wrapper, and content areas.

Use iconOpen and iconClose to customize expand/collapse indicators, and renderItem for full control over each accordion item layout and behavior.

Import Component From Library

react
1import { Accordion } from "@neuctra/ui";

Basic Usage Code

Start with a simple accordion. The component supports collapsible content sections with customizable headers and icons.

jsx
1import { Accordion } from '@neuctra/ui';
2
3function BasicExample() {
4  const items = [
5    {
6      title: "What is Neuctra UI?",
7      content: "Neuctra UI is a modern React component library.",
8    },
9    {
10      title: "Is it customizable?",
11      content: "Yes, fully customizable via className and styles.",
12    }
13  ];
14
15  return (
16    <Accordion items={items} />
17  );
18}

Basic Example

Neuctra UI is a modern, customizable React component library.
Yes, fully customizable via className and inline styles.
Yes, built-in dark mode support using Tailwind classes.

Advanced Usage

Neuctra UI is a modern, customizable React component library.
Yes, fully customizable via className and inline styles.
Yes, built-in dark mode support using Tailwind classes.
Neuctra UI is a modern, customizable React component library.
Yes, fully customizable via className and inline styles.
Yes, built-in dark mode support using Tailwind classes.
Neuctra UI is a modern, customizable React component library.
Yes, fully customizable via className and inline styles.
Yes, built-in dark mode support using Tailwind classes.

Props Table

PropTypeDefaultDescription
AccordionItem{ title: string | ReactNode; content: ReactNode }—Shape used by each item in items
itemsAccordionItem[]—List of accordion items
allowMultiplebooleanfalseAllow multiple open items
defaultOpennumber[][]Indexes open by default
classNamestring—Root class
styleCSSProperties—Root inline styles
itemClassNamestring—Item wrapper class
itemStyleCSSProperties—Item wrapper inline styles
headerClassNamestring—Header class
contentClassNamestring—Content class
headerStyleCSSProperties—Header inline styles
titleClassNamestring—Title span class
titleStyleCSSProperties—Title span inline styles
iconClassNamestring—Icon wrapper class
iconStyleCSSProperties—Icon wrapper inline styles
contentWrapperClassNamestring—Collapsible wrapper class
contentWrapperStyleCSSProperties—Collapsible wrapper inline styles
contentStyleCSSProperties—Content inline styles
hoverClassNamestring—Additional classes applied to header
hoverStyleCSSProperties—Additional inline styles on header
borderColorstring"var(--border)"Available in the type for custom integrations
radiusstring | number"0.5rem"Available in the type for custom integrations
shadowstring"none"Available in the type for custom integrations
durationnumber300Animation duration (ms)
iconOpenReactNode—Custom open icon
iconCloseReactNode—Custom close icon
renderItemfunction—Fully custom render logic

Common Mistakes

<Accordion defaultOpen={1} />

defaultOpen must be an array of indexes.

<Accordion items={[]} />

Ensure items array is not empty.

<Accordion className="max-w-lg" />

Use className for layout control.

Pro Tips

  • Use allowMultiple for FAQ-style layouts.
  • Use renderItem for full custom UI control.
  • Combine className + style for maximum flexibility.
  • Keep content lightweight for better performance.
  • Use Tailwind dark classes for automatic dark mode.

Frequently Asked Questions

How do I install and import the Accordion component?

Install the @neuctra/ui package, then import it with: import { Accordion } from "@neuctra/ui";

Can I customize the Accordion component's appearance?

Yes. Accordion accepts a className prop for custom Tailwind CSS classes, so you can adjust spacing, layout, and styling without overriding the component internals.

Is the Accordion component accessible?

Accordion is built with semantic HTML and standard ARIA attributes, and supports keyboard navigation and focus states out of the box, so it works well with screen readers and keyboard-only users.

Built with React, Tailwind CSS & TypeScript.