Accordion

An accordion is a container for multiple accordion items.

size 
density 
isQuiet 
isDisabled 
allowsMultipleExpanded 
import {Accordion, AccordionItem, AccordionItemTitle, AccordionItemPanel} from '@react-spectrum/s2';
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};

<Accordion styles={style({width: 220})}>
  <AccordionItem id="personal">
    <AccordionItemTitle>Personal Information</AccordionItemTitle>
    <AccordionItemPanel>Personal information form here.</AccordionItemPanel>
  </AccordionItem>
  <AccordionItem id="billing">
    <AccordionItemTitle>Billing Address</AccordionItemTitle>
    <AccordionItemPanel>Billing address form here.</AccordionItemPanel>
  </AccordionItem>
</Accordion>

Expanding

Use the defaultExpandedKeys or expandedKeys prop to set the expanded items, and onExpandedChange to handle user interactions. The expanded keys correspond to the id prop of each <AccordionItem>.

Application settings content

import {Accordion, AccordionItem, AccordionItemTitle, AccordionItemPanel, type Key} from '@react-spectrum/s2';
import {useState} from 'react';

function Example() {
  let [expandedKeys, setExpandedKeys] = useState(new Set<Key>(['settings']));

  return (
    <Accordion
      expandedKeys={expandedKeys}
      onExpandedChange={setExpandedKeys}>
      <AccordionItem id="settings">
        <AccordionItemTitle>Settings</AccordionItemTitle>
        <AccordionItemPanel>Application settings content</AccordionItemPanel>
      </AccordionItem>
      <AccordionItem id="preferences">
        <AccordionItemTitle>Preferences</AccordionItemTitle>
        <AccordionItemPanel>User preferences content</AccordionItemPanel>
      </AccordionItem>
      <AccordionItem id="advanced">
        <AccordionItemTitle>Advanced</AccordionItemTitle>
        <AccordionItemPanel>Advanced configuration options</AccordionItemPanel>
      </AccordionItem>
    </Accordion>
  );
}

Content

Use AccordionItemHeader to add additional elements alongside the title, such as action buttons or icons.

import {Accordion, AccordionItem, AccordionItemTitle, AccordionItemPanel, AccordionItemHeader, ActionButton} from '@react-spectrum/s2';
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};

<Accordion>
  <AccordionItem styles={style({width: 250})}>
    <AccordionItemHeader>
      <AccordionItemTitle>Project Settings</AccordionItemTitle>
      <ActionButton>Edit</ActionButton>
    </AccordionItemHeader>
    <AccordionItemPanel>
      Configure your project settings including name, description, and permissions.
    </AccordionItemPanel>
  </AccordionItem>
  <AccordionItem id="preferences">
    <AccordionItemTitle>Preferences</AccordionItemTitle>
    <AccordionItemPanel>User preferences content</AccordionItemPanel>
  </AccordionItem>
</Accordion>

API

<Accordion>
  <AccordionItem>
    <AccordionItemHeader>
      <AccordionItemTitle />
    </AccordionItemHeader>
    <AccordionItemPanel />
  </AccordionItem>
</Accordion>

Accordion

NameTypeDefault
childrenReact.ReactNodeDefault:
The accordion item elements in the accordion.
stylesDefault:
Spectrum-defined styles, returned by the style() macro.
size'S''M''L''XL'Default: 'M'
The size of the accordion.
density'compact''regular''spacious'Default: 'regular'
The amount of space between the accordion items.
isQuietbooleanDefault:
Whether the accordion should be displayed with a quiet style.
allowsMultipleExpandedbooleanDefault:
Whether multiple accordion items can be expanded at the same time.
isDisabledbooleanDefault:
Whether all accordion items are disabled.
expandedKeysIterable<Key>Default:
The currently expanded keys in the accordion (controlled).
defaultExpandedKeysIterable<Key>Default:
The initial expanded keys in the accordion (uncontrolled).

AccordionItem

A accordion item is a collapsible section of content. It is composed of a header with a heading and trigger button, and a panel that contains the content.

NameTypeDefault
size'S''M''L''XL'Default: 'M'
The size of the accordion item.
density'compact''regular''spacious'Default: 'regular'
The amount of space between the accordion item.
isQuietbooleanDefault:
Whether the accordion item should be displayed with a quiet style.
childrenReactNodeDefault:
The contents of the accordion item, consisting of a accordion item title and accordion item panel.
idKeyDefault:
An id for the accordion item, matching the id used in expandedKeys.
isDisabledbooleanDefault:
Whether the accordion item is disabled.
isExpandedbooleanDefault:
Whether the accordion item is expanded (controlled).
defaultExpandedbooleanDefault:
Whether the accordion item is expanded by default (uncontrolled).
stylesDefault:
Spectrum-defined styles, returned by the style() macro.

AccordionItemHeader

A wrapper element for the accordion item title that can contain other elements not part of the trigger.

NameType
childrenReact.ReactNode
The contents of the accordion item header.

AccordionItemTitle

An accordion item title consisting of a heading and a trigger button to expand/collapse the panel.

NameTypeDefault
levelnumberDefault: 3
The heading level of the accordion item title.
childrenReact.ReactNodeDefault:
The contents of the accordion item title.

AccordionItemPanel

An accordion item panel is a collapsible section of content that is hidden until the accordion item is expanded.

NameType
childrenReact.ReactNode
The contents of the accordion item panel.