Collapsible
One panel that shows or hides optional detail under its title, such as fees. The most useful line stays visible; the rest opens under it.
Ritla scan of this preview: 41 of 41 checks3 breakpointsScanned
Preview
Mirrored is the same English content laid out right to left: it separates a mirroring bug from a translation one.
Installation
Add the component
npx ritla add collapsibleAlso works with shadcn:
npx shadcn@latest add @ritla/collapsibleDependencies it brings
@base-ui/react@phosphor-icons/reactOr copy by hand
Installing by hand copies the component's source into your project. The source comes with a Ritla UI license, so the CLI is the short way to the same files.
Usage
import { Collapsible, CollapsibleRow } from "@/components/ui/collapsible";<Collapsible title="Fees and exchange rate" summary={<CollapsibleRow label="Total fee">JOD 0.500</CollapsibleRow>}> <CollapsibleRow label="Transfer fee">JOD 0.500</CollapsibleRow> <CollapsibleRow label="Arrives">Today</CollapsibleRow></Collapsible>Examples
Open and controlled
open and onOpenChange to control it; here it starts open, with no summary line. Use Accordion for several sections.
API reference
Collapsible
| Prop | Type | Default | Description |
|---|---|---|---|
title | ReactNode | None | Figma's Title: the trigger row's label. |
summary | ReactNode | None | Stays visible under the title: the most useful line. |
children | ReactNode | None | The detail that opens under the summary, its items 8px apart. |
defaultOpen | boolean | false | Figma's Open, at first. |
open / onOpenChange | boolean | None | Controls whether it's open. |
disabled | boolean | false | Stops it opening or closing. |
CollapsibleRow
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | None | The row's label, at its start. |
children | ReactNode | None | The value, at the row's end. Format amounts with formatNumber. |
Usage guidelines
A collapsible hides one block of detail that only some people need, and keeps its summary line visible. Accordion, Collapsible or FAQ section, what fits in a panel, and the checks before handoff.
1. Accordion, Collapsible or FAQ section
Accordions hide detail that only some people need. If everyone needs the content, show it. Pick the part by how many panels there are and where they sit.
| You need to | Use | Why |
|---|---|---|
| Answer many questions in a stack, opened one by one | Accordion item | People scan the questions and open only theirs. |
| Hide one block of optional detail, such as fees | Collapsible (this page) | A single panel with a summary line that stays visible. |
| Add a full FAQ block to a marketing page | FAQ section, Accordion types | A ready section with heading, questions and a contact link. |
| Show five or fewer short answers | FAQ section, Simple types | Short answers read faster when they are all open. |
| Switch between views of equal weight | Tabs | Only one view shows, and every view has a name. |
2. What fits in a panel
A panel holds a short answer: a paragraph, a short list or a link to more. Keep required content and form fields out of accordions; people skip closed panels.
Do
- Put a paragraph, a short list or a link in a panel.
- Link to a full article when the answer is long.
- Use Divider=True between items in a stack.
Don't
- Nest an accordion inside an accordion.
- Hide required form fields or legal terms people must read.
- Put the only way to finish a task inside a closed panel.
Before handoff
- Questions are written the way people ask them.
- The default open state is marked, and deep links open their item.
- Content everyone needs is not hidden.
- Arabic stacks use the RTL variant.
- Mobile uses Breakpoint=Mobile.
Accessibility
Keyboard
Keys are written for left-to-right. In right-to-left the arrow keys swap: the one pointing toward the reading direction moves forward.
| Key | Action |
|---|---|
| EnterSpace | Opens or closes the panel. |
ARIA
- The whole title row is the button, not only the icon, with
aria-expandedandaria-controls. - The row is 48px tall. Opening and closing take 200ms, and are instant under reduced motion.
- Find-in-page opens the panel when it finds the text inside.
Arabic and RTL notes
Mirrors
- The title sits on the right and the caret at the row's end: the left.
- In a
CollapsibleRowthe label sits on the right and the value on the left.
Does not mirror
- The up-down caret doesn't mirror.
- Numerals
- Amounts follow the numerals setting; format them with
formatNumber. An exchange rate reads in its language's order: 1 JOD = 1.41 USD. - Arabic typography
- The title is
label-14Semibold; heights are minimums. - Mixed-direction text
- Values that can arrive in either language get
dir="auto".
Checks it passes
The Ritla checks this component satisfies by construction. Used as documented, it does not bring these defects onto your page.
- Clipped text: content wider than its box with overflow hidden and no ellipsis
- Fixed-pixel-width container whose Arabic text exceeds the space
- Arabic text falling back past the declared font family (measured, declared, or a webfont that failed to load)
- letter-spacing applied to Arabic text (breaks the connected script)