lara-light-indigo

Accordion

Accordion groups a collection of contents in tabs.

Default
Multiple
Programmatic
Custom Headers
Import via Module

import { Accordion, AccordionTab } from 'primereact/accordion';
 
Import via CDN

<script src="https://unpkg.com/primereact/core/core.min.js"></script>
<script src="https://unpkg.com/primereact/accordion/accordion.min.js"></script>
 
Getting Started

Accordion element consists of one or more AccordionTab elements and can either be used as a Controlled or Uncontrolled component.

Controlled Component

In controlled mode, activeIndex and onTabChange properties need to be defined to control the state.


<Accordion activeIndex={activeIndex} onTabChange={(e) => setActiveIndex(e.index)}>
    <AccordionTab header="Header I">
        Content I
    </AccordionTab>
    <AccordionTab header="Header II">
        Content II
    </AccordionTab>
    <AccordionTab header="Header III">
        Content III
    </AccordionTab>
</Accordion>
 
Uncontrolled

In uncontrolled mode, no additional properties are required. Initial active tab can be provided using the activeIndex property in uncontrolled mode however it is evaluated at initial rendering and ignored in further updates. If you programmatically need to update the active tab, prefer to use the component as controlled.


<Accordion>
    <AccordionTab header="Header I">
        Content I
    </AccordionTab>
    <AccordionTab header="Header II">
        Content II
    </AccordionTab>
    <AccordionTab header="Header III">
        Content III
    </AccordionTab>
</Accordion>
 
Multiple

By default only one tab at a time can be active, enabling multiple property changes this behavior to allow multiple tabs be active at the same time.


<Accordion multiple>
    <AccordionTab header="Header I">
        Content I
    </AccordionTab>
    <AccordionTab header="Header II">
        Content II
    </AccordionTab>
    <AccordionTab header="Header III">
        Content III
    </AccordionTab>
</Accordion>
 
Properties For AccordionTab
NameTypeDefaultDescription
headerstringnullOrientation of tab headers.
disabledbooleanfalseWhether the tab is disabled.
styleobjectnullInline style of the tab header and content.
classNamestringnullStyle class of the tab header and content.
headerStyleobjectnullInline style of the tab header.
headerClassNamestringnullStyle class of the tab header.
headerTemplateanynullTemplate of the tab header.
contentStyleobjectnullInline style of the tab content.
contentClassNamestringnullStyle class of the tab content.
tabIndexnumbernullIndex of the element in tabbing order.
Properties
NameTypeDefaultDescription
idstringnullUnique identifier of the element.
activeIndexanynullActive index or indexes of the element. Use an array of numbers for multiple indexes. the "multiple" prop must be set to true in order to specify multiple indexes.
classNamestringnullStyle class of the element.
styleobjectnullInline style of the element.
multiplebooleanfalseWhen enabled, multiple tabs can be activated at the same time.
expandIconstringpi pi-chevron-rightIcon of a collapsed tab.
collapseIconstringpi pi-chevron-downIcon of an expanded tab.
transitionOptionsobjectnullThe properties of CSSTransition can be customized, except for "nodeRef" and "in" properties.
Events
NameParametersDescription
onTabOpenevent.originalEvent: browser event
event.index: Index or indexes of the tab (number or array of numbers).
Callback to invoke when a tab gets expanded.
onTabCloseevent.originalEvent: browser event
event.index: Index of the tab
Callback to invoke when an active tab is collapsed by clicking on the header.
onTabChangeevent.originalEvent: browser event
event.index: Index of the tab
Callback to invoke when state of the accordion changes.
Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
p-accordionContainer element.
p-accordion-headerHeader of a tab.
p-accordion-contentContainer of a tab.
Accessibility

This section is under development. After the necessary tests and improvements are made, it will be shared with the users as soon as possible.

Dependencies
  • react-transition-group

Component Scale

Input Style

Ripple Effect

Free Themes

Built-in component themes created by the PrimeReact Theme Designer.

Bootstrap
Blue
Purple
Blue
Purple
Material Design
Indigo
Deep Purple
Indigo
Deep Purple
Material Design Compact
Indigo
Deep Purple
Indigo
Deep Purple
Tailwind
Tailwind Light
Fluent UI
Blue
PrimeOne Design - 2022 NEW
Lara Indigo
Lara Blue
Lara Purple
Lara Teal
Lara Indigo
Lara Blue
Lara Purple
Lara Teal
PrimeOne Design - 2021
Saga Blue
Saga Green
Saga Orange
Saga Purple
Vela Blue
Vela Green
Vela Orange
Vela Purple
Arya Blue
Arya Green
Arya Orange
Arya Purple
Premium Themes

Premium themes are only available exclusively for PrimeReact Theme Designer subscribers and therefore not included in PrimeReact core.

Soho Light
Soho Dark
Viva Light
Viva Dark
Mira
Nano

Legacy Free Themes

Nova
Nova Alt
Nova Accent
Luna Blue
Luna Green
Luna Amber
Luna Pink
Rhea

Premium Create-React-App Templates

Beautifully crafted premium create-react-app application templates by the PrimeTek design team.

Sakai
Atlantis
Freya
Ultima
Diamond
Sapphire
Serenity
Babylon
Avalon
Apollo
Roma