Talisman LogoTalisman Logo Design System
Browse documentation
Components

Collapsible

A block of content that one trigger shows or hides, with no styling of its own so you design the trigger.

Stableimport { Collapsible } from "@repo/ui/collapsible";Source

Select the button to show the details.

When to use

  • To hide secondary detail that most people do not need on every visit, such as the technical data of a process or a long log.
  • To keep a page short and scannable, so the main content stays in view. This follows Structure you can scan in the manifesto.
  • For one block with its own trigger, placed anywhere in a layout.

When not to use

  • Several related sections that behave together. Use Accordion, which manages which item is open.
  • Content people need every time. Show it. Hidden content is skipped.
  • A short message or help text. Use a Tooltip or a Popover.
  • A task that interrupts the flow. Use Dialog.

Anatomy

Part Role
Collapsible Holds the open state. Controlled with open or uncontrolled with defaultOpen.
CollapsibleTrigger The control that toggles. Use asChild with a Button.
CollapsibleContent The block that shows and hides. It animates its height.

Collapsible has no visuals. You design the trigger and the layout around it. Put the trigger and the content under the same Collapsible.

Examples

Closed by default

Open by default

Use defaultOpen when most people need the content, but should be able to hide it.

Número: 0001234-56.2024.8.26.0100

Vara: 3ª Vara Cível

Distribuição: 14/03/2024

Controlled

Control open when something else depends on it, such as the trigger label or analytics.

Disabled

Content

  • The trigger names what it shows: “Mostrar 3 comentários”, “Histórico de revisões”.
  • Add a count or a state when the hidden content has one.
  • Change the label or rotate a chevron when open, so the state is visible and not only in the layout.

Do and don’t

DoName what is hidden and how much of it.
Don'tDon't use a vague trigger like “Mais”. People do not know what they will get.

Accessibility

  • Built on Radix Collapsible. The trigger is a button with aria-expanded and aria-controls pointing to the content, and data-state set to open or closed.
  • Keyboard: Space and Enter toggle it. Tab order is the trigger, then the content when it is open.
  • When closed, the content is hidden (hidden), so it is not read and its controls are not reachable.
  • With asChild, the child must be a real button, so keyboard and role come for free. A div with onClick loses them.
  • With disabled, the trigger has disabled and cannot be toggled.
  • The height animation is animate-collapsible-down and -up, and it does not stop for prefers-reduced-motion (see Known issues).

Code

import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@repo/ui/collapsible";
import { Button } from "@repo/ui/button";

<Collapsible>
  <CollapsibleTrigger asChild>
    <Button size="xs" variant="ghost">
      Mostrar 3 comentários
    </Button>
  </CollapsibleTrigger>
  <CollapsibleContent>
    <Comments />
  </CollapsibleContent>
</Collapsible>;

Props

Collapsible
PropTypeDefaultDescription
defaultOpenbooleanfalseInitial open state when the collapsible is uncontrolled
disabledbooleanfalsePrevents the user from toggling the content
onOpenChange(open: boolean) => void—Called when the open state changes
openboolean—Controlled open state
CollapsibleTrigger
PropTypeDefaultDescription
asChildbooleanfalseRenders the child element instead of a button. Use it with a `Button`.
CollapsibleContent
PropTypeDefaultDescription
forceMountboolean—Keeps the content in the DOM when closed, for animation libraries or search by text.

Known issues

Issue Effect
CollapsibleContent uses animate-collapsible-down and animate-collapsible-up with no motion-reduce variant. The height animation runs for people who set reduced motion, against the repository rule to honor prefers-reduced-motion.
CollapsibleTrigger has no styles. Without asChild and a Button, the trigger is an unstyled button with no focus or hover feedback. Always style it.
Edit this page on GitHub