Skip to main content

Accordion

The TkAccordion component is a user interface element that organizes content under headers, allowing users to expand and collapse sections by clicking on each header. It is particularly useful for improving layout and readability on pages with extensive information.

import { TkAccordion, TkAccordionItem } from '@takeoff-ui/react'

Type​

Establishes 2 different accordion styles grouped, divided via type property.

Grouped
Panel 1 Title
Panel 1 Content
Panel 2 Title
Panel 2 Content
Panel 3 Title
Panel 3 Content

Divided
Panel 1 Title
Panel 1 Content
Panel 2 Title
Panel 2 Content
Panel 3 Title
Panel 3 Content
View Code
<TkAccordion allow-multiple="false" type="grouped">
<TkAccordionItem icon="flight">
<span slot="header">Panel 1 Title</span>
<div slot="content">Panel 1 Content</div>
</TkAccordionItem>
<TkAccordionItem icon="flight">
<span slot="header">Panel 2 Title</span>
<div slot="content">Panel 2 Content</div>
</TkAccordionItem>
<TkAccordionItem icon="travel">
<span slot="header">Panel 3 Title</span>
<div slot="content">Panel 3 Content</div>
</TkAccordionItem>
</TkAccordion>

<TkAccordion allow-multiple="true" type="divided">
<TkAccordionItem size="base" icon="flight">
<span slot="header">Panel 1 Title</span>
<div slot="content">Panel 1 Content</div>
</TkAccordionItem>
<TkAccordionItem icon="flight">
<span slot="header">Panel 2 Title</span>
<div slot="content">Panel 2 Content</div>
</TkAccordionItem>
<TkAccordionItem icon="travel">
<span slot="header">Panel 3 Title</span>
<div slot="content">Panel 3 Content</div>
</TkAccordionItem>
</TkAccordion>

Arrow Position​

Provides 2 positions for opening and closing arrows left, right via arrowPosition property.

Right Positioned Arrows
Panel 1 Title
Panel 1 Content
Panel 2 Title
Panel 2 Content
Panel 3 Title
Panel 3 Content

Left Positioned Arrows
Panel 1 Title
Panel 1 Content
Panel 2 Title
Panel 2 Content
Panel 3 Title
Panel 3 Content
View Code
<TkAccordion arrow-position="left">
<TkAccordionItem size="base" icon="flight">
<span slot="header">Panel 1 Title</span>
<div slot="content">Panel 1 Content</div>
</TkAccordionItem>
<TkAccordionItem icon="flight">
<span slot="header">Panel 2 Title</span>
<div slot="content">Panel 2 Content</div>
</TkAccordionItem>
<TkAccordionItem icon="travel">
<span slot="header">Panel 3 Title</span>
<div slot="content">Panel 3 Content</div>
</TkAccordionItem>
</TkAccordion>

Expand and Collapse Icons​

Provides different icon options for expand and collapse expandIcon and collapseIcon properties.

Panel 1 Title
Panel 1 Content
Panel 2 Title
Panel 2 Content
View Code
<TkAccordion expand-icon="add" collapse-icon="remove">
<TkAccordionItem icon="flight">
<span slot="header">Panel 1 Title</span>
<div slot="content">Panel 1 Content</div>
</TkAccordionItem>
<TkAccordionItem icon="flight">
<span slot="header">Panel 2 Title</span>
<div slot="content">Panel 2 Content</div>
</TkAccordionItem>
</TkAccordion>

Accordion API​

Props​

NameTypeDefaultDescription
number, number[], string, string[]nullCurrently active panel indexes. Can be a single value or an array. When allowMultiple is false, only the last value in the array will be used.
booleanfalseAllows multiple accordion items to be expanded simultaneously.
"left", "right"'right'Sets the position of opening and closing chevrons.
IIconOptions, string'keyboard_arrow_up'Sets the collapse icon
IIconOptions, string'keyboard_arrow_down'Sets the expand icon
booleanfalseWhether to hide the arrow icons.
"divided", "grouped"'grouped'Sets accordion style for the component.

Events​

NameDescription
tkAccordionItemSelectedEmitted when an accordion item is selected

Slots​

NameDescription
defaultDefault slot to detect TkAccordionItem components.

Interfaces​

interface IAccordionItemSelect {
index: string | number;
active: boolean;
}

Accordion Item API​

Props​

NameTypeDefaultDescription
booleanfalseSets if the accordion is active.
stringnullHeader text to display.
IIconOptions, stringnullIcon for accordion component.
stringnullOptional key for the accordion item.
"base", "large"'base'Sets size for the component.
()=>voidnullToggle's the accordion item.

Slots​

NameDescription
contentCustom content template.
headerCustom header template that overrides the header prop if provided.