Skip to main content

Accordion

Accordions are navigational elements that allow to structure content title-like and focus the view by hiding content.

One advantages of accordions is that they support in getting an overview before focusing on details. Additionally, accordions help to structure and display larger content on a single page. Nevertheless preventing scrolling should not be the only reason for making use of an accordion.

Accordions are more suitable when people need only a few key pieces of content on a single page.

Example

Live Editor
Result
Loading...

Headline

Live Editor
Result
Loading...

List

Live Editor
Result
Loading...

Variants

Background Color

To customize the background color of headline accordion, you can use the backgroundColor prop.

You can also use any color code in hex, rgb, rgba, or hsl formats.

Live Editor
Result
Loading...

Badge

To display a badge you can use the badge prop.

Live Editor
Result
Loading...

Bordered

To display a bordered variant can use the bordered prop.

Live Editor
Result
Loading...

Checkbox

You can display a checkbox for accordion header.

the list type accordion headers can't have item based checkbox. If you using the list type accordion please use selectable prop instead. It's adds all accordion headers checkbox.

If you use the headline type accordion, you can use the selectable prop to make all items with the checkbox. Or you can add the checkboxes to your items separately.

To use item based checkbox in the accordion header, you need to add to your item object the isSelectable property.

You can also change the checkbox state for the expanded accordion item header. To use this feature, you need to add to your item object the checkboxType property. It's takes two type of value checked or indeterminate by default it's a checked.

You can isolate and customize the checkbox component utilizing isolateCheckbox, combined with onItemUpdate, callback.

Live Editor
Result
Loading...

onItemUpdate

onItemUpdate is a callback prop that informs the parent component about the set of information that belongs to the clicked accordion item when the user clicks on the accordion header. These parameters are: id: clicked item id. isExpanded: a boolean value returns true if the clicked item is expanded. isCustomCheckbox: a boolean value returns true if the clicked area is a custom checkbox.

This callback allows you to modify accordion item properties at the parent component when the user clicks on the accordion item header or custom checkbox.

Live Editor
Result
Loading...

Count

You can display a count on accordion headers.

To display a count value you need to add to your item object count property with its content.

Live Editor
Result
Loading...

Data Props

The below example shows component support for data props.

Live Editor
Result
Loading...

Disabled

To disable a accordion item you need to add isDisabled property to your item object.

If you prefer to make all accordion items disabled, you can use the disabled prop.

Live Editor
Result
Loading...

Expanded

To make accordion item open by default you can add the isExpanded property to your item object.

Live Editor
Result
Loading...

Nested

The accordion component supports nested items. You can find below the example of data for using the accordion component nested option.

info

Nested items are available to use only for the list type accordion.

Live Editor
Result
Loading...

Toggle Position

You can change the toggle arrow button position with the togglePosition prop. The toggle button can be used at the accordion header's right and left positions.

By default, the toggle button position is right side.

info

togglePosition prop is available to use only for the list type accordion.

Live Editor
Result
Loading...

Tooltip

You can display a tooltip for each accordion item title. To display a tooltip you need to add to your item object tooltipContent property with its content.

Live Editor
Result
Loading...

Examples

Working with Checkbox List

Accordion can select or unselect all the items in a checkbox list by combining checkboxState, checkboxType and onUpdateAccordion.

Live Editor
Result
Loading...

Props

NameTypeDefault
type *
type of accordion
"headline" | "list"
data *
accordion data
AccordionItem[]
bordered
makes accordion headers bordered - for list type only
boolean
disabled
makes all accordion items disabled
boolean
onItemUpdate
callback for getting clicked item id, expand status and type (clicked item is custom checkbox or accordion header)
((id: string | number, isExpanded: boolean, isCustomCheckbox: boolean) => void)
selectable
makes all items selectable
boolean
togglePosition
toggle button position - for list type only
"left" | "right"
backgroundColor
background color of headline
string
data-{foo}
Data attributes can be used by testing libraries to retrieve components or assert their existence
string
* - the prop is required.