Skip to content

Collapsible

Get Ritla UI

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

Open in Figma

Preview

Mirrored is the same English content laid out right to left: it separates a mirroring bug from a translation one.

PreviewCode
EnglishMirroredArabic
LTR →

Installation

  1. Add the component

    npx ritla add collapsible

    Also works with shadcn: npx shadcn@latest add @ritla/collapsible

  2. Dependencies it brings

    @base-ui/react@phosphor-icons/react

  3. Or 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

collapsible.tsx
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.

EnglishMirroredArabic
LTR →

API reference

Collapsible

PropTypeDefaultDescription
titleReactNodeNoneFigma's Title: the trigger row's label.
summaryReactNodeNoneStays visible under the title: the most useful line.
childrenReactNodeNoneThe detail that opens under the summary, its items 8px apart.
defaultOpenbooleanfalseFigma's Open, at first.
open / onOpenChangebooleanNoneControls whether it's open.
disabledbooleanfalseStops it opening or closing.

CollapsibleRow

PropTypeDefaultDescription
labelReactNodeNoneThe row's label, at its start.
childrenReactNodeNoneThe 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 toUseWhy
Answer many questions in a stack, opened one by oneAccordion itemPeople scan the questions and open only theirs.
Hide one block of optional detail, such as feesCollapsible (this page)A single panel with a summary line that stays visible.
Add a full FAQ block to a marketing pageFAQ section, Accordion typesA ready section with heading, questions and a contact link.
Show five or fewer short answersFAQ section, Simple typesShort answers read faster when they are all open.
Switch between views of equal weightTabsOnly 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.

KeyAction
EnterSpaceOpens or closes the panel.

ARIA

  • The whole title row is the button, not only the icon, with aria-expanded and aria-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 CollapsibleRow the 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-14 Semibold; 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.

  • R042Clipped text: content wider than its box with overflow hidden and no ellipsis
  • R043Fixed-pixel-width container whose Arabic text exceeds the space
  • R050Arabic text falling back past the declared font family (measured, declared, or a webfont that failed to load)
  • R051letter-spacing applied to Arabic text (breaks the connected script)