Collapsible

new

Not to be confused with the three-time TI champion. A trigger that shows and hides a block of content.

Demo

@kappa starred 3 repositories

unovue/reka-ui

Open Props in the corner of the example to try disabled.

disabled locks the trigger, and the content stays as it is, open or closed.

Installation

Usage

<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'
</script>

<template>
  <Collapsible>
    <CollapsibleTrigger as-child>
      <Button variant="soft" color="neutral">Show details</Button>
    </CollapsibleTrigger>
    <CollapsibleContent>Anything, from a paragraph to a table.</CollapsibleContent>
  </Collapsible>
</template>

The trigger has no styles of its own, so wrap a Button in it with as-child. The content animates open and closed.

Closed content stays in the page, so Ctrl+F finds it and opens the collapsible on a match, and the server-rendered HTML includes the text. Same trade-off as Accordion: the content is mounted from the start, so set unmount-on-hide when it's heavy.

Examples

Icon

Put a chevron in the trigger and rotate it on open: [&[data-state=open]>svg]:rotate-180 on the Button, plus a transition on the icon.

Icon

Controlled

v-model:open holds the state, so a button elsewhere can drive it. default-open starts it open without taking control.

Controlled
Both buttons drive the same open ref.

Unmount on hide

unmount-on-hide removes the content while it's closed. Ctrl+F can't find it then.

Unmount

Heavy content

Three hundred rows open and close as fast as three: the height is measured up front, so the animation never waits on layout. Collapse would approve.

Heavy content

Motion

DurationEasing
Open--transition-duration-medium-1--ease-emphasized-decelerate
Close--transition-duration-short-4--ease-standard-decelerate

Same timing as Accordion. overflow: hidden applies only during the animation, so a Select or Popover inside an open panel can spill out of it. With reduced motion, the content just appears and disappears.

The utilities are animate-collapsible-down and animate-collapsible-up from @kappa-ui/core/tailwind.css.

API Reference

Every part takes a class that merges with its own. On CollapsibleContent, it styles the block inside the animated panel, so padding, a border or a display class never reach the element that hidden="until-found" hides.

Data attributes

data-slotAttributesDescription
collapsibledata-state, data-disabledThe root.
collapsible-triggerdata-state, data-disabled, aria-expanded, aria-controlsThe button, or the child it renders with as-child.
collapsible-contentdata-state, data-disabled, hiddenThe animated panel; hidden="until-found" while closed, or empty and hidden with unmount-on-hide.

Keyboard

KeyAction
SpaceOpens or closes the content.
EnterOpens or closes the content.

Changelog

  1. registry 0.23.0

    bc6008b — Exits now use the decelerating curve, like entrances. Collapsible, Accordion, the overlay surfaces (Popover, Select, Menu, Tooltip), Drawer, Toast and InnerLoading used to close on --ease-emphasized-accelerate, which holds still for most of its duration and then snaps shut; closing on --ease-standard-decelerate starts at once and settles gently, so the same duration feels faster. The tokens themselves are unchanged.

  2. core 0.17.0

    bc6008b — Exits now use the decelerating curve, like entrances. Collapsible, Accordion, the overlay surfaces (Popover, Select, Menu, Tooltip), Drawer, Toast and InnerLoading used to close on --ease-emphasized-accelerate, which holds still for most of its duration and then snaps shut; closing on --ease-standard-decelerate starts at once and settles gently, so the same duration feels faster. The tokens themselves are unchanged.

  3. registry 0.22.0

    b827f85 — An open AccordionContent no longer clips its content: the accordion keyframes clip while the panel's height animates, as Collapsible's do, and the part drops its permanent overflow-hidden, so a focus ring or a shadow inside an open answer shows in full.

    7dffb11 — CollapsibleContent puts its class on a new div inside the animated panel, as AccordionContent does, so padding, a border or a display class no longer keep a closed panel visible: Chromium left an empty strip, and Safari, which has no hidden="until-found", showed closed content styled with a display class. The DOM gains that inner div; a selector or style that targeted the panel element through your class now finds it one level down.

    d5720b8 — An autoresize Textarea mounted while hidden (a closed tab, a Collapsible, a hidden md:block column) measures itself when it shows instead of staying collapsed until the user types, and it re-measures by itself when its width changes.

  4. core 0.16.0

    b827f85 — An open AccordionContent no longer clips its content: the accordion keyframes clip while the panel's height animates, as Collapsible's do, and the part drops its permanent overflow-hidden, so a focus ring or a shadow inside an open answer shows in full.

  5. registry 0.7.0

    7323be6 — Collapsible: Collapsible, CollapsibleTrigger and CollapsibleContent over Reka UI's collapsible. The content animates with the accordion's timing; closed content stays in the page as hidden="until-found" unless unmount-on-hide is set.