Accordion
A set of collapsible panels with headings.
View as MarkdownAnatomy
Import the component and assemble its parts:
import { Accordion } from '@base-ui-components/react/accordion';
<Accordion.Root>
<Accordion.Item>
<Accordion.Header>
<Accordion.Trigger />
</Accordion.Header>
<Accordion.Panel />
</Accordion.Item>
</Accordion.Root>
API reference
Root
Groups all parts of the accordion.
Renders a <div>
element.
defaultValue
any[]
any[]
- Name
- Description
The uncontrolled value of the item(s) that should be initially expanded.
To render a controlled accordion, use the
value
prop instead.- Type
any[]
value
any[]
any[]
- Name
- Description
The controlled value of the item(s) that should be expanded.
To render an uncontrolled accordion, use the
defaultValue
prop instead.- Type
any[]
onValueChange
function
function
- Name
- Description
Event handler called when an accordion item is expanded or collapsed. Provides the new value as an argument.
- Type
((value: any[]) => void)
- Name
- Description
Allows the browser’s built-in page search to find and expand the panel contents.
Overrides the
keepMounted
prop and useshidden="until-found"
to hide the element without removing it from the DOM.- Type
boolean
- Default
false
openMultiple
boolean
(default: true
)
boolean
true
- Name
- Description
Whether multiple items can be open at the same time.
- Type
boolean
- Default
true
disabled
boolean
(default: false
)
boolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean
- Default
false
loop
boolean
(default: true
)
boolean
true
- Name
- Description
Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.
- Type
boolean
- Default
true
orientation
Orientation
(default: 'vertical'
)
Orientation
'vertical'
- Name
- Description
The visual orientation of the accordion. Controls whether roving focus uses left/right or up/down arrow keys.
- Type
Orientation
- Default
'vertical'
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: Accordion.Root.State) => string)
keepMounted
boolean
(default: false
)
boolean
false
- Name
- Description
Whether to keep the element in the DOM while the panel is closed. This prop is ignored when
hiddenUntilFound
is used.- Type
boolean
- Default
false
render
ReactElement | function
ReactElement | function
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Accordion.Root.State) => ReactElement)
data-orientation
Indicates the orientation of the accordion.
data-disabled
Present when the accordion is disabled.
Item
Groups an accordion header with the corresponding panel.
Renders a <div>
element.
value
AccordionItemValue
AccordionItemValue
- Name
- Type
AccordionItemValue
onOpenChange
function
function
- Name
- Description
Event handler called when the panel is opened or closed.
- Type
((open: boolean) => void)
disabled
boolean
(default: false
)
boolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean
- Default
false
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: Accordion.Item.State) => string)
render
ReactElement | function
ReactElement | function
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Accordion.Item.State) => ReactElement)
data-open
Present when the accordion item is open.
data-disabled
Present when the accordion item is disabled.
data-index
Indicates the index of the accordion item.
Header
A heading that labels the corresponding panel.
Renders an <h3>
element.
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: Accordion.Item.State) => string)
render
ReactElement | function
ReactElement | function
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Accordion.Item.State) => ReactElement)
data-open
Present when the accordion item is open.
data-disabled
Present when the accordion item is disabled.
data-index
Indicates the index of the accordion item.
Trigger
A button that opens and closes the corresponding panel.
Renders a <button>
element.
nativeButton
boolean
(default: true
)
boolean
true
- Name
- Description
Whether the component renders a native
<button>
element when replacing it via therender
prop. Set tofalse
if the rendered element is not a button (e.g.<div>
).- Type
boolean
- Default
true
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: Accordion.Item.State) => string)
render
ReactElement | function
ReactElement | function
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Accordion.Item.State) => ReactElement)
data-panel-open
Present when the accordion panel is open.
data-disabled
Present when the accordion item is disabled.
Panel
A collapsible panel with the accordion item contents.
Renders a <div>
element.
- Name
- Description
Allows the browser’s built-in page search to find and expand the panel contents.
Overrides the
keepMounted
prop and useshidden="until-found"
to hide the element without removing it from the DOM.- Type
boolean
- Default
false
className
string | function
string | function
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string
| ((state: Accordion.Item.State) => string)
keepMounted
boolean
(default: false
)
boolean
false
- Name
- Description
Whether to keep the element in the DOM while the panel is closed. This prop is ignored when
hiddenUntilFound
is used.- Type
boolean
- Default
false
render
ReactElement | function
ReactElement | function
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElement
or a function that returns the element to render.- Type
| ReactElement
| ((props: HTMLProps, state: Accordion.Item.State) => ReactElement)
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-index
Indicates the index of the accordion item.
data-starting-style
Present when the panel is animating in.
data-ending-style
Present when the panel is animating out.
--accordion-panel-height
The accordion panel's height.
--accordion-panel-width
The accordion panel's width.