suiss/ui · Component
Accordion
A vertically stacked set of headings that each reveal a section of content.
Accordion is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Accordion wraps the accordion primitive of the chosen base. An Accordion holds one or more AccordionItem parts; each item pairs an AccordionTrigger with an AccordionContent panel. The trigger renders inside a heading element and shows a caret that flips between down and up as the panel opens and closes.
Use an accordion to shorten long pages of related content, such as FAQs or settings groups, where people only need one or a few sections at a time. For a single show-and-hide region, a collapsible is a lighter fit.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
- Install the following dependencies and add the
cnhelper:
- Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Composition
Use the following composition to build a Accordion:
Examples
Filled
Set variant="filled" to place the items on a rounded bg-muted surface.
By default
Use defaultValue to open an item on first render.
Use defaultExpandedKeys to open an item on first render.
Multiple
Set multiple to keep several panels open at once.
Set type="multiple" to keep several panels open at once.
Set allowsMultipleExpanded to keep several panels open at once.
Accessibility
- Each trigger is a
buttonwitharia-expandedreflecting its panel's state. - Triggers are wrapped in a heading element.
- Triggers are reachable with Tab;
EnterandSpacetoggle the focused panel. - Disabled triggers receive
aria-disabledand are dimmed withopacity-50.
API Reference
Accordion
The root that groups items and manages which panels are open.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "filled" | "default" |
| Prop | Type | Default |
|---|---|---|
multiple | boolean | false |
defaultValue | any[] | — |
value | any[] | — |
onValueChange | (value: any[]) => void | — |
| Prop | Type | Default |
|---|---|---|
type | "single" | "multiple" | — |
collapsible | boolean | false |
defaultValue | string | string[] | — |
value | string | string[] | — |
onValueChange | (value: string | string[]) => void | — |
| Prop | Type | Default |
|---|---|---|
allowsMultipleExpanded | boolean | false |
defaultExpandedKeys | Iterable<Key> | — |
expandedKeys | Iterable<Key> | — |
onExpandedChange | (keys: Set<Key>) => void | — |
Also accepts the props of the primitive part it wraps.
The default variant is plain with dividers; filled adds a rounded bg-muted container.
Only one panel is open at a time by default, and opening another closes the previous one. The open state is an array of item values. Use defaultValue, such as ["shipping"], for uncontrolled use, or value with onValueChange to control it. onValueChange is called when an item opens or closes.
type is required: "single" keeps one panel open at a time, and "multiple" lets several stay open. With "single", add collapsible so the open panel can be closed again. The open state is one item value with "single" and an array with "multiple". Use defaultValue, such as "shipping" or ["shipping"], for uncontrolled use, or value with onValueChange to control it. onValueChange is called when an item opens or closes.
Only one panel is open at a time by default, and opening another closes the previous one. The open state is a set of item ids. Use defaultExpandedKeys, such as ["shipping"], for uncontrolled use, or expandedKeys with onExpandedChange to control it. onExpandedChange is called when an item opens or closes.
AccordionItem
A single section that pairs a trigger with its panel.
| Prop | Type | Default |
|---|---|---|
value | any | — |
disabled | boolean | false |
| Prop | Type | Default |
|---|---|---|
value | string | — |
disabled | boolean | false |
| Prop | Type | Default |
|---|---|---|
id | Key | value |
value | string | — |
isDisabled | boolean | disabled |
disabled | boolean | — |
Also accepts the props of the primitive part it wraps.
Give each item a unique value; it identifies the item in the open state. disabled stops the item from opening or closing.
Each item needs a unique value; it identifies the item in the open state. disabled stops the item from opening or closing.
Give each item a unique id; it identifies the item in the expanded keys. value is used as the id when id is not set, and disabled as isDisabled. isDisabled stops the item from opening or closing.
AccordionTrigger
The button, inside a heading, that toggles its item's panel and shows the caret indicator.
Also accepts the props of the primitive part it wraps.
AccordionContent
The collapsible panel holding the item's content.
Also accepts the props of the primitive part it wraps.
className applies to the inner padded wrapper, not the animated panel.
The panel animates with animate-accordion-down and animate-accordion-up on data-open and data-closed.
The panel animates with animate-accordion-down and animate-accordion-up on data-state="open" and data-state="closed".
The panel animates open with animate-accordion-down inside an expanded item, and renders its content only while the item is expanded.
Each part sets a data-slot, such as accordion-item or accordion-trigger-icon, for styling.
Web preview
Accordion groups AccordionItems, each with an AccordionTrigger and an AccordionContent panel. The root and items are Reanimated views with a layout transition, so items below move smoothly as a panel opens or closes, and the trigger's caret rotates as it opens.
The default variant draws items on the page background separated by hairlines. The filled variant puts the whole list on a rounded bg-muted surface, which suits grouped settings or FAQ cards.
Installation
- Install the following dependencies:
- Copy and paste the following code into
components/ui/accordion.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
- Copy and paste the following code into
components/ui/accordion.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
- Copy and paste the following code into
components/ui/accordion.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Default
Web preview
Filled
Set variant="filled" to put the list on a rounded bg-muted surface.
Web preview
Multiple
Only one item is open at a time by default. Set multiple so several items stay open; this example is controlled.
Web preview
Accessibility
- The header row has the
headerrole, and the trigger has thebuttonrole withexpandedanddisabledaccessibility state. - Closed panels are hidden from VoiceOver and TalkBack.
- A disabled trigger is shown at 50% opacity.
API Reference
Accordion
Root that holds the open state and lays out the items.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "filled" | "default" |
Also accepts the props of React.ComponentProps<typeof AccordionPrimitive.Root>.
Give each AccordionItem a value. Use defaultValue, an array of item values, for uncontrolled state, or value with onValueChange to control it. Set multiple to let several items stay open, disabled on the root or on a single item to block toggling, and keepMounted to keep closed panels mounted. Animations respect the system Reduce Motion setting. accordionVariants is also exported if you need the classes elsewhere.
AccordionItem
One section, separated from the previous one by a hairline.
Also accepts the props of React.ComponentProps<typeof AccordionPrimitive.Item>.
AccordionTrigger
Pressable heading row with a rotating caret.
Also accepts the props of React.ComponentProps<typeof AccordionPrimitive.Trigger>.
The trigger label underlines while pressed.
AccordionContent
Panel shown while the item is open; fades out upward on close.
| Prop | Type | Default |
|---|---|---|
className | string | - |
Also accepts the props of React.ComponentProps<typeof AccordionPrimitive.Panel>.
className is merged onto the root element.
Accordion
Root that holds the open state and lays out the items.
| Parameter | Type | Default |
|---|---|---|
_Â variant | Variant: .default | .filled | .default |
multiple | Bool | false |
content | () -> Content | - |
expanded | Binding<Set<Value>> | - |
Overloads: init(_:multiple:content:), init(_:expanded:multiple:content:), init(_:expanded:content:).
AccordionItem
One section, separated from the previous one by a hairline.
| Parameter | Type | Default |
|---|---|---|
value | Value | - |
content | () -> Content | - |
label | () -> Label | - |
_Â title | LocalizedStringKey | - |
Overloads: init(value:content:label:), init(_:value:content:).
AccordionVariant
Values: Default, Filled.
Accordion
Root that holds the open state and lays out the items.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
variant | AccordionVariant: Default | Filled | AccordionVariant.Default |
content | @Composable () -> Unit | - |
AccordionItem
One section, separated from the previous one by a hairline.
| Parameter | Type | Default |
|---|---|---|
expanded | Boolean | - |
onExpandedChange | (Boolean) -> Unit | - |
title | String | - |
modifier | Modifier | Modifier |
enabled | Boolean | true |
content | @Composable ColumnScope.() -> Unit | - |
trigger | @Composable RowScope.() -> Unit | - |
Overloads: AccordionItem(expanded, onExpandedChange, title, content), AccordionItem(expanded, onExpandedChange, trigger, content).