Accordion
Stacked sections whose headers show and hide their content, one or several at a time.
Not in 0.1.0 yet
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 {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@neshel-ui/components";Usage
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
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | — |
| collapsible | boolean | false | Whether the open item can be closed again (default false). |
| defaultValue | string | null | — | Initially open item when uncontrolled. |
| disabled | boolean | — | Disable every item. |
| headingLevel | 2 | 3 | 4 | 5 | 6 | — | Heading level of the item headers (2–6, default 3). |
| hiddenUntilFound | boolean | — | Closed panels use hidden="until-found" so in-page search can open them (implies keepMounted). |
| keepMounted | boolean | — | Keep closed panels in the DOM (hidden). |
| onValueChange | (value: string | null) => void | — | — |
| ref | Ref<HTMLDivElement> | — | — |
| type | "single" | — | One open item at most (default). |
| value | string | null | — | Controlled open item (null = none). |
Also accepts the props of: React DOM attributes.
AccordionMultipleProps
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | — |
| defaultValue | readonly string[] | — | Initially open items when uncontrolled. |
| disabled | boolean | — | Disable every item. |
| headingLevel | 2 | 3 | 4 | 5 | 6 | — | Heading level of the item headers (2–6, default 3). |
| hiddenUntilFound | boolean | — | Closed panels use hidden="until-found" so in-page search can open them (implies keepMounted). |
| keepMounted | boolean | — | Keep closed panels in the DOM (hidden). |
| onValueChange | (value: string[]) => void | — | — |
| ref | Ref<HTMLDivElement> | — | — |
| type(required) | "multiple" | — | Any number of open items. |
| value | readonly string[] | — | Controlled open items. |
Also accepts the props of: React DOM attributes.
AccordionItemProps
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | — |
| disabled | boolean | — | — |
| ref | Ref<HTMLDivElement> | — | — |
| value(required) | string | — | Unique value of the item within its accordion. |
Also accepts the props of: React DOM attributes.
AccordionTriggerProps
| Prop | Type | Default | Description |
|---|---|---|---|
| asChild | boolean | — | Render the single child element as the trigger (it must render a <button>). |
| children | ReactNode | — | — |
| ref | Ref<HTMLButtonElement> | — | — |
Also accepts the props of: React DOM attributes.
AccordionContentProps
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | — |
| hiddenUntilFound | boolean | — | Overrides the accordion's hiddenUntilFound for this panel. |
| keepMounted | boolean | — | Overrides the accordion's keepMounted for this panel. |
| ref | Ref<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/defaultValueare a string ornull;onValueChangereceives the open value ornull. Withoutcollapsible, activating the open header keeps it open.type="multiple":value/defaultValueare string arrays;onValueChangereceives the list.
"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 witharia-expandedandaria-controls; panels are labelled by their header. - Disabled items cannot be toggled and are skipped by arrow navigation.
keepMountedkeeps closed panels in the DOM (hidden);hiddenUntilFoundlets the browser's in-page search open them.- The optional height transition stops under
prefers-reduced-motion.
Keyboard
| Key | Action |
|---|---|
| Enter / Space | Toggle the focused section |
| ArrowDown / ArrowUp | Move to the next / previous header (wraps) |
| Home / End | Move to the first / last header |
| Tab | Move 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
keepMountedorhiddenUntilFound. - There is no horizontal orientation.
Related
One disclosure without a heading: Collapsible. See also choosing components.