Accordion
Accordions provide a way to restrict Card components to only open one at a time.
Examples
Accordions use Card components to provide styling of the Accordion components. Use AccordionToggle to provide a button that switches between each AccordionCollapse component.
Basic Example
Fully Collapsed State
If you want your Accordion to start in a fully-collapsed state, then simply don't pass in a defaultActiveKey prop to Accordion.
Entire Header Clickable
Each of the Card components in the Accordion can have their entire header clickable, by setting the AccordionToggle's underlying component to be a CardHeader component.
Custom Toggle
You can now hook into the Accordion toggle functionality via useAccordionToggle to make custom toggle components.
API
Accordionview source file
import Accordion from 'react-bootstrap/Accordion'Copy import code for the Accordion component| Name | Type | Default | Description |
|---|---|---|---|
| activeKey | string | The current active key that corresponds to the currently expanded card | |
| as | elementType | Set a custom element for this component | |
| defaultActiveKey | string | The default active key that is expanded on start | |
| bsPrefix | string | 'accordion' | Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css. |
Accordion.Toggleview source file
import Accordion from 'react-bootstrap/Accordion'Copy import code for the Accordion component| Name | Type | Default | Description |
|---|---|---|---|
| as | elementType | Set a custom element for this component | |
| children | element | Children prop should only contain a single child, and is enforced as such | |
| eventKey required | string | A key that corresponds to the collapse component that gets triggered when this has been clicked. | |
| onClick | function | A callback function for when this component is clicked |
Accordion.Collapseview source file
import Accordion from 'react-bootstrap/Accordion'Copy import code for the Accordion component| Name | Type | Default | Description |
|---|---|---|---|
| children required | element | ||
| eventKey required | string | A key that corresponds to the toggler that triggers this collapse's expand or collapse. |
useAccordionToggle
import { useAccordionToggle } from 'react-bootstrap/AccordionToggle'; const decoratedOnClick = useAccordionToggle(eventKey, onClick);