Accordions allow you to hide and show content in a container under a header.
Accordion consist of an outer accordion component and inner accordion items. Each item has a optional button and panel. The button is used to toggle the panel's visibility.
rc.accordion(
rc.accordion_item(
rc.accordion_button(
rc.heading("Example"),
rc.accordion_icon(),
),
rc.accordion_panel(
rc.text(
"This is an example of an accordion component."
)
),
),
allow_toggle=True,
width="100%",
)
An accordion can have multiple items.
rc.accordion(
rc.accordion_item(
rc.accordion_button(
rc.heading("Example 1"),
rc.accordion_icon(),
),
rc.accordion_panel(
rc.text(
"This is an example of an accordion component."
)
),
),
rc.accordion_item(
rc.accordion_button(
rc.heading("Example 2"),
rc.accordion_icon(),
),
rc.accordion_panel(
rc.text(
"This is an example of an accordion component."
)
),
),
allow_multiple=True,
bg="black",
color="white",
width="100%",
)
You can create multilevel accordions by nesting accordions within the outer accordion panel.
rc.accordion(
rc.accordion_item(
rc.accordion_button(
rc.accordion_icon(),
rc.heading("Outer"),
),
rc.accordion_panel(
rc.accordion(
rc.accordion_item(
rc.accordion_button(
rc.accordion_icon(),
rc.heading("Inner"),
),
rc.accordion_panel(
rc.badge(
"Inner Panel",
variant="solid",
color_scheme="green",
),
),
)
),
),
),
width="100%",
)
You can also create an accordion using the shorthand syntax.
Pass a list of tuples to the items
prop.
Each tuple should contain a label and a panel.
rc.accordion(
items=[
("Label 1", rc.center("Panel 1")),
("Label 2", rc.center("Panel 2")),
],
width="100%",
)
rc.Accordion
The wrapper that uses cloneElement to pass props to AccordionItem children.
Event Triggers
See the full list of default event triggersrc.AccordionButton
The button that toggles the expand/collapse state of the accordion item. This button must be wrapped in an element with role heading.
Props
No component specific props
Event Triggers
See the full list of default event triggersrc.AccordionPanel
The container for the details to be revealed.
Props
No component specific props
Event Triggers
See the full list of default event triggersrc.AccordionIcon
A chevron-down icon that rotates based on the expanded/collapsed state.
Props
No component specific props