Skip to main content

Accordion

An accessible way for the user to expand and collapse content.

installversionusage
yarn add @ciceksepeti/cui-accordion1.0.0import {`Accordion, AccordionHeader, AccordionButton, AccordionContent`} from '@ciceksepeti/cui-accordion'

Content​

An accordion is a vertically stacked set of interactive headings that each contain a title, content snippet, or thumbnail representing a section of content. The headings function as controls that enable users to reveal or hide their associated sections of content. Accordions are commonly used to reduce the need to scroll when presenting multiple sections of content on a single page.

An accordion element consists of an AccordionHeader that has AccordionButton inside itself and AccordionContent that keep your content. Cactus UI provides Accordion component to group them.

Examples​

Default​

Example of a default behavior of Accordion component.

import React from 'react';
import {
Accordion,
AccordionHeader,
AccordionButton,
AccordionContent,
} from '@ciceksepeti/cui-accordion';

function Demo() {
return (
<Accordion>
<AccordionHeader>
<AccordionButton>Step 1</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 1: Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.
</AccordionContent>
<AccordionHeader>
<AccordionButton disabled>Step 2</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 2: Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.
</AccordionContent>
<AccordionHeader>
<AccordionButton>Step 3</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 3: Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.
</AccordionContent>
</Accordion>
);
}
PREVIEW
Accordion Default Preview

Single​

Example of a single behavior of Accordion component. single={false} means that you can open more than one section at a time.

import React from 'react';
import {
Accordion,
AccordionHeader,
AccordionButton,
AccordionContent,
} from '@ciceksepeti/cui-accordion';

function Demo() {
return (
<Accordion single={false}>
<AccordionHeader>
<AccordionButton>Step 1</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 1: Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.
</AccordionContent>
<AccordionHeader>
<AccordionButton disabled>Step 2</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 2: Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.
</AccordionContent>
<AccordionHeader>
<AccordionButton>Step 3</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 3: Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.
</AccordionContent>
</Accordion>
);
}
PREVIEW
Accordion Single Behavior Preview

Collapsible​

Example of a collapsible behavior of Accordion component. collapsible={false} prevent the user from closing the section that is expanded.

import React from 'react';
import {
Accordion,
AccordionHeader,
AccordionButton,
AccordionContent,
} from '@ciceksepeti/cui-accordion';

function Demo() {
return (
<Accordion collapsible={false}>
<AccordionHeader>
<AccordionButton>Step 1</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 1: Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.
</AccordionContent>
<AccordionHeader>
<AccordionButton disabled>Step 2</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 2: Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.
</AccordionContent>
<AccordionHeader>
<AccordionButton>Step 3</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 3: Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.
</AccordionContent>
</Accordion>
);
}
PREVIEW
Accordion Collapsible Behavior Preview

Default Indexes​

Example of a using indexes prop of Accordion component. defaultIndexes={[Some index here]} allows users to set sections that expanded initially. defaultIndexes prop is a way to create an uncontrolled accordion component.

import React from 'react';
import {
Accordion,
AccordionHeader,
AccordionButton,
AccordionContent,
} from '@ciceksepeti/cui-accordion';

function Demo() {
return (
<Accordion defaultIndexes={[1, 3]}>
<AccordionHeader>
<AccordionButton>Step 1</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 1: Lorem Ipsum is simply dummy text of the printing and typesetting
industry.
</AccordionContent>
<AccordionHeader>
<AccordionButton disabled>Step 2</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 2: Lorem Ipsum is simply dummy text of the printing and typesetting
industry.
</AccordionContent>
<AccordionHeader>
<AccordionButton>Step 3</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 3: Lorem Ipsum is simply dummy text of the printing and typesetting
industry.
</AccordionContent>
<AccordionHeader>
<AccordionButton>Step 4</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 4: Lorem Ipsum is simply dummy text of the printing and typesetting
industry.
</AccordionContent>
<AccordionHeader>
<AccordionButton>Step 5</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 5: Lorem Ipsum is simply dummy text of the printing and typesetting
industry.
</AccordionContent>
</Accordion>
);
}
PREVIEW
Accordion Default Indexes Behavior Preview

Indexes​

Example of a using indexes prop of Accordion component. indexes={[Some index here]} allows users to set sections that expanded initially. Indexes prop must be used with onChange event to accordion work properly.

import React from 'react';
import {
Accordion,
AccordionHeader,
AccordionButton,
AccordionContent,
} from '@ciceksepeti/cui-accordion';

function Demo() {
return (
<Accordion indexes={[0, 2, 4]}>
<AccordionHeader>
<AccordionButton>Step 1</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 1: Lorem Ipsum is simply dummy text of the printing and typesetting
industry.
</AccordionContent>
<AccordionHeader>
<AccordionButton disabled>Step 2</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 2: Lorem Ipsum is simply dummy text of the printing and typesetting
industry.
</AccordionContent>
<AccordionHeader>
<AccordionButton>Step 3</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 3: Lorem Ipsum is simply dummy text of the printing and typesetting
industry.
</AccordionContent>
<AccordionHeader>
<AccordionButton>Step 4</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 4: Lorem Ipsum is simply dummy text of the printing and typesetting
industry.
</AccordionContent>
<AccordionHeader>
<AccordionButton>Step 5</AccordionButton>
</AccordionHeader>
<AccordionContent>
Step 5: Lorem Ipsum is simply dummy text of the printing and typesetting
industry.
</AccordionContent>
</Accordion>
);
}
PREVIEW
Accordion Indexes Behavior Preview

Props​

Accordion Props​

Accordion Events​

AccordionHeader Props​

AccordionButton Props​

Playground​

/img/codesandbox-icon

Styling​

tip

To learn more about selectors please visit the CSS Selector Reference page.

Name

Type

[data-cui-accordion]

Element Selector

[data-cui-accordion-header]

Element Selector

[data-cui-accordion-button]

Element Selector

[data-cui-accordion-content]

Element Selector

[data-cui-accordion-button][aria-expanded='true']

Element Selector

[data-cui-accordion-button][aria-disabled='true']

Element Selector

[data-cui-accordion-content][data-expanded='true']

Element Selector