@biem/ui

Accordion

A stack of sections that lets users show and hide content.

An accordion stacks sections of content and keeps each one closed until users open it. Each trigger names its section, so users can scan the stack and read only the content they need.

Usage

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

export function AccordionDefault() {
	return (
		<Accordion>
			<AccordionItem>
				<AccordionTrigger>Stock transfer</AccordionTrigger>
				<AccordionContent>
					The warehouse ships 12 cases on Monday, and the store receives them on Tuesday.
				</AccordionContent>
			</AccordionItem>
			<AccordionItem>
				<AccordionTrigger>Delivery window</AccordionTrigger>
				<AccordionContent>
					The store accepts deliveries from 6:00 to 8:00, before it opens.
				</AccordionContent>
			</AccordionItem>
			<AccordionItem>
				<AccordionTrigger>Returns</AccordionTrigger>
				<AccordionContent>
					The store sends damaged items back with the next delivery.
				</AccordionContent>
			</AccordionItem>
		</Accordion>
	);
}

Examples

Open by Default

One section often holds what most users come for, such as the status of an open order. Listed in defaultValue, that section is already open when the accordion appears, and users remain free to close it or to open another.

The warehouse ships 12 cases on Monday, and the store receives them on Tuesday.

Controlled

Other parts of an interface sometimes decide which section is open, for example a warning that points to the section explaining its cause. Through value and onValueChange, the application keeps track of the open sections and can open the right one, so users arrive directly at the explanation they need.

The warehouse ships 12 cases on Monday, and the store receives them on Tuesday.

Multiple

When users compare two sections, such as the terms of two suppliers, they need both open at once. By default, opening a section closes the one that was open. Once multiple is set, several sections stay open together, so users keep both in view.

The warehouse ships 12 cases on Monday, and the store receives them on Tuesday.

The store accepts deliveries from 6:00 to 8:00, before it opens.

With Frame

Next to tables and charts, an accordion can blend into the content around it. Wrapped in AccordionFrame, its sections form one self-contained unit, so users see at once which content belongs to the group.

Disabled

While the figures inside an accordion are being recalculated, its sections should stay as they are. Through disabled, the accordion holds every section in its current state, so users can neither open nor close one before the figures are complete.

Disabled Item

Sometimes only one section is unavailable, for instance because users lack the permission for its content. That item alone then carries disabled, so users cannot open or close it, yet they still see that it exists while every other section works as before.

API Reference

Accordion

Propvalue
Typeany[]
Default–
DescriptionSets the values of the open items and makes the accordion controlled. Update it in onValueChange.
PropdefaultValue
Typeany[]
Default–
DescriptionSets the values of the items that are open at first render. The accordion then tracks the open items itself.
ProponValueChange
Type(value: any[], eventDetails: AccordionRootChangeEventDetails) => void
Default–
DescriptionRuns when users open or close an item. It receives the values of the items that are open afterwards.
Propmultiple
Typeboolean
Defaultfalse
DescriptionLets users keep several items open at the same time. Without it, opening an item closes the open one.
Propdisabled
Typeboolean
Defaultfalse
DescriptionPrevents users from opening or closing any item.
ProphiddenUntilFound
Typeboolean
Defaultfalse
DescriptionLets the browser's page search find text in closed items and open them. The content of closed items then stays in the DOM, and keepMounted has no effect.
PropkeepMounted
Typeboolean
Defaultfalse
DescriptionKeeps the content of closed items in the DOM. It has no effect when hiddenUntilFound is set.
Proprender
TypeReactElement | render function
Default–
DescriptionReplaces the native element or composes the accordion with another component.

AccordionItem

Propvalue
Typeany
Default–
DescriptionIdentifies the item in value and defaultValue of the accordion. Without it, the item gets a generated ID.
ProponOpenChange
Type(open: boolean, eventDetails: AccordionItemChangeEventDetails) => void
Default–
DescriptionRuns when users open or close the item.
Propdisabled
Typeboolean
Defaultfalse
DescriptionPrevents users from opening or closing the item.
Proprender
TypeReactElement | render function
Default–
DescriptionReplaces the native element or composes the item with another component.

AccordionTrigger

Proprender
TypeReactElement | render function
Default–
DescriptionReplaces the native element or composes the trigger with another component.
PropnativeButton
Typeboolean
Defaulttrue
DescriptionDeclares whether the rendered element is a native button. Set it to false when render returns a different element.
Propdisabled
Typeboolean
Defaultfalse
DescriptionPrevents users from opening or closing the item with this trigger. A disabled item or accordion disables the trigger as well.

AccordionContent

ProphiddenUntilFound
Typeboolean
Default–
DescriptionLets the browser's page search find text in this content while its item is closed, and open the item. Without it, the content uses the value set on the accordion.
PropkeepMounted
Typeboolean
Default–
DescriptionKeeps this content in the DOM while its item is closed. Without it, the content uses the value set on the accordion.
Proprender
TypeReactElement | render function
Default–
DescriptionReplaces the native element or composes the content with another component.