Accordion
Usage
Custom control label
Change chevron
With icons
Change transition
To change transition duration, set transitionDuration
prop:
To disable transitions, set transitionDuration
to 0:
Default opened items
When multiple={false}
, set defaultValue
as string:
When multiple={true}
, set defaultValue
as an array of strings:
Control state
When multiple={false}
, set value
as string:
When multiple={true}
, set value
as an array of strings:
Compose controls
You can add any additional elements that will be displayed next to Accordion.Control
,
for example, you can add ActionIcon or Menu:
Disabled items
Set disabled
prop on Accordion.Control
component to disable it.
Disabled items cannot be activated with mouse or keyboard, will be skipped when user navigates with arrow keys:
Unstyled Accordion
Set unstyled
prop on Accordion component to remove all non-essential library styles.
It can be used to style component with Styles API without overriding any styles.
Styles API
Use Styles API to customize Accordion styles:
Data attributes
Accordion elements have data-
attributes that can be used with Styles API:
data-active
attribute is added toAccordion.Item
root element when associated panel is expandeddata-rotate
attribute is added to chevron icon when icon should rotate (controlled bydisableChevronRotation
and expanded state of associated panel)
TypeScript
AccordionProps
type exported from @mantine/core
is a generic, it accepts boolean type that
describes multiple
state:
Accessibility
Accordion component follows WAI-ARIA recommendations on accessibility.
Notes
Set order
on Accordion
component to wrap accordion controls with h2-h6 heading.
The following example will wrap controls with h3 tag:
Keyboard interactions
Key | Description |
---|---|
ArrowDown | Moves focus to next item |
ArrowUp | Moves focus to previous item |
Home | Moves focus to first item |
End | Moves focus to last item |
Space/Enter | Toggles focused item opened state |
Accordion component props
Name | Type | Description |
---|---|---|
chevron | ReactNode | Replaces chevron on all items |
chevronPosition | "left" | "right" | Determines position of the chevron |
chevronSize | string | number | Chevron size |
children * | ReactNode | Accordion content |
defaultValue | string | string[] | Default value for uncontrolled component |
disableChevronRotation | boolean | Determines whether chevron rotation should be disabled |
id | string | Base id, used to generate ids that connect labels with controls, by default generated randomly |
loop | boolean | Determines whether arrow key presses should loop though items (first to last and last to first) |
multiple | boolean | Determines whether multiple items can be opened at a time |
onChange | (value: AccordionValue<Multiple>) => void | Callback for controlled component |
order | 2 | 3 | 4 | 5 | 6 | Heading order, has no effect on visuals |
radius | number | "xs" | "sm" | "md" | "lg" | "xl" | Key of theme.radius or any valid CSS value to set border-radius, ignored when variant="default" |
transitionDuration | number | Transition duration in ms, set 0 to disable transitions |
value | string | string[] | Value for controlled component |
variant | "default" | "contained" | "filled" | "separated" | Controls visuals |
AccordionControl component props
Name | Type | Description |
---|---|---|
chevron | ReactNode | Custom chevron icon |
children | ReactNode | Control label |
disabled | boolean | Disables control button |
icon | ReactNode | Icon rendered next to label |
AccordionItem component props
Name | Type | Description |
---|---|---|
value * | string | Value that is used to manage accordion state |
AccordionPanel component props
Name | Type | Description |
---|---|---|
children | ReactNode | Panel content |
Accordion component Styles API
Name | Static selector | Description |
---|---|---|
item | .mantine-Accordion-item | Accordion item wrapper |
itemTitle | .mantine-Accordion-itemTitle | Optional heading element wrapping control |
control | .mantine-Accordion-control | Control root |
label | .mantine-Accordion-label | Control label |
icon | .mantine-Accordion-icon | Control icon |
chevron | .mantine-Accordion-chevron | Control chevron icon |
panel | .mantine-Accordion-panel | Panel root |
content | .mantine-Accordion-content | Panel content |