DisclosureReact
A set of collapsible panels with headings.
Rendered by React 19.3.1
Loading React…Installation
npm i @hamur/reactNot on npm yet. The package goes out under the chosen name.
Anatomy
Import the component and assemble its parts:
<Accordion.Root>
<Accordion.Item>
<Accordion.Header>
<Accordion.Trigger />
</Accordion.Header>
<Accordion.Panel />
</Accordion.Item>
</Accordion.Root>Examples
Multiple
multiple lets several panels stay open at once.
Hidden Until Found
hiddenUntilFound keeps closed panels searchable; find in page opens the match.
API reference
15 props across 5 parts, in React syntax. className, style, render are listed once, under Shared props.
HeaderAccordion.Header
A heading that labels the corresponding panel. Renders a <h3>.
| Data attribute | Description |
|---|---|
data-index | Indicates the index of the accordion item. |
data-disabled | Present when the accordion item is disabled. |
data-open | Present when the accordion item is open. |
ItemAccordion.Item
Groups an accordion header with the corresponding panel. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
valueA unique value that identifies this accordion item. | any | — |
onOpenChangeEvent handler called when the panel is opened or closed. | ((open: boolean, eventDetails: AccordionItemChangeEventDetails) => void) | — |
disabledWhether the component should ignore user interaction. | boolean | false |
| Data attribute | Description |
|---|---|
data-index | Indicates the index of the accordion item. |
data-disabled | Present when the accordion item is disabled. |
data-open | Present when the accordion item is open. |
PanelAccordion.Panel
A collapsible panel with the accordion item contents. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
hiddenUntilFoundAllows the browser's built-in page search to find and expand the panel contents. | boolean | false |
keepMountedWhether to keep the element in the DOM while the panel is closed. | boolean | false |
| Data attribute | Description |
|---|---|
data-index | Indicates the index of the accordion item. |
data-open | Present when the accordion panel is open. |
data-orientation | Indicates the orientation of the accordion. |
data-disabled | Present when the accordion item is disabled. |
data-starting-style | Present when the panel begins animating in. |
data-ending-style | Present when the panel is animating out. |
| CSS variable | Description |
|---|---|
--accordion-panel-height | The accordion panel's height. |
--accordion-panel-width | The accordion panel's width. |
RootAccordion.Root
Groups all parts of the accordion. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
defaultValueThe uncontrolled value of the item(s) that should be initially expanded. | AccordionValue<TValue> | — |
valueThe controlled value of the item(s) that should be expanded. | AccordionValue<TValue> | — |
onValueChangeEvent handler called when an accordion item is expanded or collapsed. | ((value: AccordionValue<TValue>, eventDetails: AccordionRootChangeEventDetails) => void) | — |
hiddenUntilFoundAllows the browser's built-in page search to find and expand the panel contents. | boolean | false |
loopFocusDeprecated following the APG guidance update | boolean | — |
multipleWhether multiple items can be open at the same time. | boolean | false |
disabledWhether the component should ignore user interaction. | boolean | false |
orientationDeprecated following the APG guidance update | Orientation | 'vertical' |
keepMountedWhether to keep the element in the DOM while the panel is closed. | boolean | false |
| Data attribute | Description |
|---|---|
data-disabled | Present when the accordion is disabled. |
data-orientation | Indicates the orientation of the accordion. |
TriggerAccordion.Trigger
A button that opens and closes the corresponding panel. Renders a <button>.
| Prop | Type | Default |
|---|---|---|
nativeButtonWhether the component renders a native <button> element when replacing it | boolean | true |
| Data attribute | Description |
|---|---|
data-index | Indicates the index of the accordion item. |
data-panel-open | Present when the accordion panel is open. |
data-disabled | Present when the trigger or its accordion item is disabled. |
Shared props
Every part that renders an element takes these.
| Prop | Type |
|---|---|
classNameCSS class applied to the element, or a function that
returns a class based on the component's state. | string | ((state: State) => string | undefined) |
styleStyle applied to the element, or a function that
returns a style object based on the component's state. | React.CSSProperties | ((state: State) => React.CSSProperties | undefined) |
renderAllows you to replace the component's HTML element
with a different tag, or compose it with another component. | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, State> |
Keyboard and accessibility
Keyboard
| Keys | Does | Part |
|---|---|---|
| EnterSpace | Opens or closes the item's panel | Trigger |
| Space | Toggles on key up, as a native button does, also when Trigger renders another element | Trigger |
Accessibility
| Part | Sets | So that |
|---|---|---|
| Header | renders an <h3> | each trigger sits in the page's heading outline |
| Trigger | aria-expanded, aria-controls to its panel while open | a screen reader says whether the section is open and where it is |
| Panel | role="region", aria-labelledby to its trigger | the open panel is a landmark named by its heading |
| Panel | hidden="until-found" with hiddenUntilFound | find in page reaches text in a closed panel and opens it |
Focus order
- Each Trigger is one tab stop, in document order.
- The content of an open Panel follows its Trigger; a closed Panel's content is skipped.