Vertically stacked expandable sections
import {Accordion} from "@peakui/react";
import {Accordion} from "@peakui/react";
export default () => (
<Accordion>
<Accordion.Item>
<Accordion.Heading>
<Accordion.Trigger>
<Accordion.Indicator />
</Accordion.Trigger>
</Accordion.Heading>
<Accordion.Panel>
<Accordion.Body />
</Accordion.Panel>
</Accordion.Item>
</Accordion>
);
<Accordion.Trigger className="px-2 py-3 text-base">
Title
<Accordion.Indicator className="text-accent" />
</Accordion.Trigger>
@layer components {
.accordion {
--accordion-radius: 1rem;
}
.accordion__trigger {
@apply font-semibold;
}
.accordion__body-inner {
@apply text-foreground;
}
}
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
The Accordion component uses these CSS classes (view source styles):
.accordion - Group container
.accordion__item - Item, draws the separator
.accordion__heading - Heading wrapper
.accordion__trigger - Trigger button
.accordion__indicator - Chevron indicator
.accordion__panel - Collapsible panel with the height animation
.accordion__body - Body wrapper
.accordion__body-inner - Inner wrapper receiving the consumer className
.accordion--surface - Filled, rounded container
[data-slot="accordion"] - The group element
[data-slot="accordion-item"] - An item
[data-slot="accordion-heading"] - The heading
[data-slot="accordion-trigger"] - The trigger button
[data-slot="accordion-indicator"] - The chevron indicator
[data-slot="accordion-panel"] - The collapsible panel
[data-slot="accordion-body"] - The body wrapper
[data-slot="accordion-body-inner"] - The inner body wrapper
--accordion-radius - Corner radius of the surface variant. Defaults to min(32px, var(--radius-3xl))
- Expanded:
[data-expanded="true"] on the panel and the indicator; [aria-expanded="true"] on the trigger
- Hover:
:hover on the trigger, pointer devices only
- Focus:
:focus-visible or [data-focus-visible="true"] on the trigger
- Disabled:
:disabled or [aria-disabled="true"] on the trigger
- No separator:
[data-hide-separator="true"] on the item
| Prop | Type | Default | Description |
|---|
variant | 'default' | 'surface' | 'default' | Visual variant |
hideSeparator | boolean | false | Hides the line between items |
allowsMultipleExpanded | boolean | false | Lets several items stay open |
expandedKeys | Iterable<Key> | - | Controlled set of open item ids |
defaultExpandedKeys | Iterable<Key> | - | Item ids open on first render |
onExpandedChange | (keys: Set<Key>) => any | - | Called when the open items change |
isDisabled | boolean | false | Disables every item |
children | ReactNode | ((values: DisclosureGroupRenderProps) => ReactNode) | - | Items, or a function of the render props |
className | string | ((values: DisclosureGroupRenderProps) => string) | - | Additional classes, or a function of the render props |
...rest | DisclosureGroupProps | - | Every other React Aria DisclosureGroup attribute |
| Prop | Type | Default | Description |
|---|
id | Key | - | Item id, matched against expandedKeys |
isDisabled | boolean | false | Disables this item |
children | ReactNode | ((values: DisclosureRenderProps) => ReactNode) | - | Heading and panel, or a function of the render props |
className | string | ((values: DisclosureRenderProps) => string) | - | Additional classes, or a function of the render props |
...rest | DisclosureProps | - | Every other React Aria Disclosure attribute |
| Prop | Type | Default | Description |
|---|
level | number | 3 | The heading level |
className | string | - | Additional classes |
...rest | HeadingProps | - | Every other attribute of a heading |
| Prop | Type | Default | Description |
|---|
children | ReactNode | ((values: ButtonRenderProps) => ReactNode) | - | Trigger content, or a function of the render props |
className | string | ((values: ButtonRenderProps) => string) | - | Additional classes, or a function of the render props |
...rest | ButtonProps | - | Every other React Aria Button attribute |
| Prop | Type | Default | Description |
|---|
children | ReactNode | - | Replaces the built-in chevron <svg> |
className | string | - | Additional classes |
...rest | SVGProps | - | Every other attribute of an <svg> |
| Prop | Type | Default | Description |
|---|
children | ReactNode | - | Content to show and hide |
className | string | ((values: DisclosurePanelRenderProps) => string) | - | Additional classes, or a function of the render props |
...rest | DisclosurePanelProps | - | Every other React Aria DisclosurePanel attribute |
| Prop | Type | Default | Description |
|---|
children | ReactNode | - | The body content |
className | string | - | Additional classes, applied to the inner wrapper |
render | DOMRenderFunction<'div', undefined> | - | Replaces the rendered <div> with your own |
...rest | HTMLAttributes<HTMLDivElement> | - | Every other attribute of a <div> |
| Prop | Type | Description |
|---|
children | (values: DisclosureGroupRenderProps) => ReactNode | Receives expandedKeys, isDisabled |
className | (values: DisclosureGroupRenderProps) => string | Same values as children |