Skip to Content
Neshel-UI
Components

Accordion

Stacked sections whose headers show and hide their content, one or several at a time.

Client component ("use client")

Not in 0.1.0 yet

This API is on the main branch but not in the 0.1.0 packages on npm. To use it today, install locally packed tarballs.

Purpose

Accordion groups related sections (an FAQ, settings groups) behind headers. Each header is a real heading that wraps a button; activating it shows or hides its section.

Import

import.tsx
import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from "@neshel-ui/components";

Usage

Preview: accordion-basic
Preview theme

Add @neshel-ui/components and import its stylesheet.

accordion-basic.tsx
import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
} from "@neshel-ui/components";

export default function AccordionBasic() {
  return (
    // Single (default) and collapsible: one section at a time, the open one can close again.
    <Accordion collapsible defaultValue="install" style={{ maxWidth: 520 }}>
      <AccordionItem value="install">
        <AccordionTrigger>How do I install it?</AccordionTrigger>
        <AccordionContent>Add @neshel-ui/components and import its stylesheet.</AccordionContent>
      </AccordionItem>
      <AccordionItem value="tailwind">
        <AccordionTrigger>Does it need Tailwind?</AccordionTrigger>
        <AccordionContent>
          No. The stylesheet is precompiled and works with plain CSS.
        </AccordionContent>
      </AccordionItem>
      <AccordionItem value="pricing" disabled>
        <AccordionTrigger>Is there a paid plan?</AccordionTrigger>
        <AccordionContent>Not yet.</AccordionContent>
      </AccordionItem>
    </Accordion>
  );
}

API

AccordionSingleProps

AccordionSingleProps
PropTypeDefaultDescription
childrenReactNode——
collapsiblebooleanfalseWhether the open item can be closed again (default false).
defaultValuestring | null—Initially open item when uncontrolled.
disabledboolean—Disable every item.
headingLevel2 | 3 | 4 | 5 | 6—Heading level of the item headers (2–6, default 3).
hiddenUntilFoundboolean—Closed panels use hidden="until-found" so in-page search can open them (implies keepMounted).
keepMountedboolean—Keep closed panels in the DOM (hidden).
onValueChange(value: string | null) => void——
refRef<HTMLDivElement>——
type"single"—One open item at most (default).
valuestring | null—Controlled open item (null = none).

Also accepts the props of: React DOM attributes.

AccordionMultipleProps

AccordionMultipleProps
PropTypeDefaultDescription
childrenReactNode——
defaultValuereadonly string[]—Initially open items when uncontrolled.
disabledboolean—Disable every item.
headingLevel2 | 3 | 4 | 5 | 6—Heading level of the item headers (2–6, default 3).
hiddenUntilFoundboolean—Closed panels use hidden="until-found" so in-page search can open them (implies keepMounted).
keepMountedboolean—Keep closed panels in the DOM (hidden).
onValueChange(value: string[]) => void——
refRef<HTMLDivElement>——
type(required)"multiple"—Any number of open items.
valuereadonly string[]—Controlled open items.

Also accepts the props of: React DOM attributes.

AccordionItemProps

AccordionItemProps
PropTypeDefaultDescription
childrenReactNode——
disabledboolean——
refRef<HTMLDivElement>——
value(required)string—Unique value of the item within its accordion.

Also accepts the props of: React DOM attributes.

AccordionTriggerProps

AccordionTriggerProps
PropTypeDefaultDescription
asChildboolean—Render the single child element as the trigger (it must render a <button>).
childrenReactNode——
refRef<HTMLButtonElement>——

Also accepts the props of: React DOM attributes.

AccordionContentProps

AccordionContentProps
PropTypeDefaultDescription
childrenReactNode——
hiddenUntilFoundboolean—Overrides the accordion's hiddenUntilFound for this panel.
keepMountedboolean—Overrides the accordion's keepMounted for this panel.
refRef<HTMLDivElement>——

Also accepts the props of: React DOM attributes.

AccordionProps is the union of the single and multiple props.

Controlled and uncontrolled

  • type="single" (default): value / defaultValue are a string or null; onValueChange receives the open value or null. Without collapsible, activating the open header keeps it open.
  • type="multiple": value / defaultValue are string arrays; onValueChange receives the list.
Preview: accordion-multiple
Preview theme

Profile settings.

accordion-multiple.tsx
"use client";
import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
  Button,
} from "@neshel-ui/components";
import { useState } from "react";

const sections = ["Profile", "Billing", "Security"];

export default function AccordionMultiple() {
  const [open, setOpen] = useState<string[]>(["Profile"]);
  return (
    <div style={{ display: "grid", gap: 12, justifyItems: "start" }}>
      <Button variant="outline" onClick={() => setOpen(open.length ? [] : sections)}>
        {open.length ? "Close all" : "Open all"}
      </Button>
      <Accordion
        type="multiple"
        value={open}
        onValueChange={setOpen}
        style={{ width: "100%", maxWidth: 520 }}
      >
        {sections.map((name) => (
          <AccordionItem key={name} value={name}>
            <AccordionTrigger>{name}</AccordionTrigger>
            <AccordionContent>{name} settings.</AccordionContent>
          </AccordionItem>
        ))}
      </Accordion>
    </div>
  );
}

Composition

AccordionTrigger accepts asChild with a child that renders a button. Accordions can be nested: the arrow keys of each one move only among its own headers.

Styling

Rules read --neshel-border, --neshel-foreground, --neshel-primary and --neshel-focus. The height transition (200 ms) is optional CSS on the panel; it is removed under reduced motion.

Errors

An unknown type, a headingLevel outside 2–6, an empty item value or an invalid asChild child throws NeshelComponentsError on the server and the client.

Accessibility

  • Headers are headings (headingLevel, default 3) containing a native button with aria-expanded and aria-controls; panels are labelled by their header.
  • Disabled items cannot be toggled and are skipped by arrow navigation.
  • keepMounted keeps closed panels in the DOM (hidden); hiddenUntilFound lets the browser's in-page search open them.
  • The optional height transition stops under prefers-reduced-motion.

Keyboard

KeyAction
Enter / SpaceToggle the focused section
ArrowDown / ArrowUpMove to the next / previous header (wraps)
Home / EndMove to the first / last header
TabMove to the next focusable element

Common mistakes

  • Putting the only copy of essential content in a closed section — keep critical information visible.
  • Choosing a heading level that skips the page outline — set headingLevel.

Limitations

  • Closed content is not in the DOM by default: in-page search and anchors cannot reach it unless you use keepMounted or hiddenUntilFound.
  • There is no horizontal orientation.

One disclosure without a heading: Collapsible. See also choosing components.

Edit on GitHub

On this page