Navigation and progress
Accordion
Sections that open and close.
Example
Each section is a CrAccordionItem with a label. For a multi-step flow, use the Stepper component instead. By default, opening a section closes the others; with multiple, several can stay open. open opens a section initially, and onCrToggle reports each opening or closing (event.detail is true when opening).
import { CrAccordion, CrAccordionItem } from '@cristal-ui/react';
export default function AccordionBasic() {
return (
<CrAccordion style={{ width: '100%' }}>
<CrAccordionItem label="Shipping" open>
Ships within 48 hours, tracking sent by email.
</CrAccordionItem>
<CrAccordionItem label="Returns">You have 30 days to change your mind.</CrAccordionItem>
<CrAccordionItem label="Warranty">Two years, parts and labor.</CrAccordionItem>
</CrAccordion>
);
}Open all
With toggleAll, an "Open all" button opens the sections one after another, then "Close all" closes them in reverse order. Several sections can then stay open.
import { CrAccordion, CrAccordionItem } from '@cristal-ui/react';
export default function AccordionExpandAll() {
return (
<CrAccordion toggleAll style={{ width: '100%' }}>
<CrAccordionItem label="Overview">A thin apple tart, ready in 45 minutes.</CrAccordionItem>
<CrAccordionItem label="Ingredients">4 apples, 1 sheet of puff pastry, 2 tbsp butter, 2 tbsp sugar.</CrAccordionItem>
<CrAccordionItem label="Steps">Roll out the pastry, slice the apples thinly, bake for 25 minutes at 400 °F.</CrAccordionItem>
</CrAccordion>
);
}Side-by-side panels
With variant="panels", the sections are vertical panels: the selected one widens, the others fold into strips with their title written vertically. One panel is always open, the first one by default. The height is set with the --cr-accordion-height CSS variable (280px by default), the strip width with --cr-accordion-fold (56px).
12 hikes
8 hikes
5 hikes
9 hikes
import { CrAccordion, CrAccordionItem } from '@cristal-ui/react';
const trails = [
{ label: 'Peaks', from: '#4c1d95', to: '#f59e0b', text: '12 hikes' },
{ label: 'Coast', from: '#0e7490', to: '#a5f3fc', text: '8 hikes' },
{ label: 'Meadow', from: '#3f6212', to: '#bef264', text: '5 hikes' },
{ label: 'Forest', from: '#14532d', to: '#4ade80', text: '9 hikes' },
];
export default function AccordionPanels() {
return (
<CrAccordion variant="panels" style={{ width: '100%' }}>
{trails.map((trail) => (
<CrAccordionItem key={trail.label} label={trail.label}>
<p style={{ margin: '0 0 8px' }}>{trail.text}</p>
<div style={{ height: 150, borderRadius: 8, background: `linear-gradient(160deg, ${trail.from}, ${trail.to})` }} />
</CrAccordionItem>
))}
</CrAccordion>
);
}Animations
animation value | Effect |
|---|---|
slide | the section unfolds smoothly (default) |
accent-bar | a gradient bar grows along the open section, and its number lights up (with numbered) |
cascade | the content comes in line by line; data-cr-count elements count up to their value and data-cr-grow elements grow from the bottom |
import { CrAccordion, CrAccordionItem } from '@cristal-ui/react';
export default function AccordionAccent() {
return (
<CrAccordion animation="accent-bar" numbered style={{ width: '100%' }}>
<CrAccordionItem label="Design">Mockups and user flows approved with the team.</CrAccordionItem>
<CrAccordionItem label="Development">Components, tests and continuous integration.</CrAccordionItem>
<CrAccordionItem label="Launch">Go live and follow up on early feedback.</CrAccordionItem>
</CrAccordion>
);
}With cascade, data-cr-count gives the final value ("19.9") of an element that contains only text: the first number in the text counts up from 0 to it, then the original text is restored. The meta slot displays a value to the right of the title, here the total or the statistic.
import { CrAccordion, CrAccordionItem } from '@cristal-ui/react';
const lines = [
{ label: 'Subscription', amount: '99', text: '$99.00' },
{ label: 'Add-ons', amount: '19.9', text: '$19.90' },
{ label: 'Tax', amount: '9.5', text: '$9.50' },
];
const views = [30, 45, 40, 60, 55, 75, 90];
export default function AccordionCascade() {
return (
<CrAccordion animation="cascade" multiple style={{ width: '100%' }}>
<CrAccordionItem label="Total">
<span slot="meta">$128.40</span>
{lines.map((line) => (
<div key={line.label} style={{ display: 'flex', justifyContent: 'space-between', padding: '4px 0' }}>
<span>{line.label}</span>
<span data-cr-count={line.amount}>{line.text}</span>
</div>
))}
</CrAccordionItem>
<CrAccordionItem label="Views this week">
<span slot="meta">4,200 (+12%)</span>
<div role="img" aria-label="Views per day: from 300 on Monday to 900 on Sunday" style={{ display: 'flex', alignItems: 'flex-end', gap: 8, height: 100 }}>
{views.map((value, day) => (
<div key={day} data-cr-grow="" style={{ flex: 1, height: `${value}%`, borderRadius: 4, background: 'var(--cr-color-primary)' }} />
))}
</div>
</CrAccordionItem>
</CrAccordion>
);
}If the user has asked their system to reduce motion, sections open without movement and the content is displayed immediately, numbers included.
Keyboard
| Key | Action |
|---|---|
| Enter, Space | opens or closes the section |
| Down / Up Arrow (Right / Left) | next / previous section header |
| Home / End | first / last header |
| Tab | moves to the next header or content |
Accessibility
- Follows the W3C "accordion" pattern (ARIA Authoring Practices): each header is a button inside a level 3 heading (
headingLevelto change it), which states whether it is open (aria-expanded) and controls a region named by that header. - A closed section is removed from the keyboard order and from screen readers.
- The chart in the "cascade" example has a
role="img"and a description: do the same for your own visuals.
API
Properties
| Property | Type | Default | Description |
|---|---|---|---|
animation | "accent-bar" | "cascade" | "slide" | 'slide' | Animation d'ouverture : slide, accent-bar (barre qui pousse sur le côté) ou cascade (le contenu arrive ligne par ligne). |
headingLevel | number | 3 | Niveau de titre des en-têtes (2 à 6). |
multiple | boolean | false | Permet d'ouvrir plusieurs sections à la fois. |
numbered | boolean | false | Numérote les sections (01, 02…). |
toggleAll | boolean | false | Ajoute un bouton « Tout ouvrir / Tout fermer » : les sections s'ouvrent l'une après l'autre, et se ferment dans l'ordre inverse. |
variant | "list" | "panels" | 'list' | Présentation : liste ou panneaux côte à côte (panels). |
Slots
| Slot | Description |
|---|---|
| default | Les sections cr-accordion-item. |
CSS parts
To style it from outside: cr-accordion::part(name) { … }
| Part | Description |
|---|---|
toggle-all | Le bouton « Tout ouvrir / Tout fermer ». |
CrAccordionItem API
Properties
| Property | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Désactive la section. |
label (obligatoire) | string | — | Titre de la section. |
open | boolean | false | Section ouverte. |
Events
| React | event.detail | Description |
|---|---|---|
onCrToggle | boolean | Émis quand la section s'ouvre ou se ferme ; detail : true si ouverte. |
Slots
| Slot | Description |
|---|---|
| default | Le contenu de la section. |
slot="meta" | Valeur affichée à droite de l'en-tête (total, statistique…). |
CSS parts
To style it from outside: cr-accordion-item::part(name) { … }
| Part | Description |
|---|---|
header | Le bouton de l'en-tête. |
panel | Le contenu. |