Collapsible
newNot to be confused with the three-time TI champion. A trigger that shows and hides a block of content.
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.
Controlled
v-model:open holds the state, so a button elsewhere can drive it. default-open starts it open without taking control.
Unmount on hide
unmount-on-hide removes the content while it's closed. Ctrl+F can't find it then.
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.
- report-001.csv
- report-002.csv
- report-003.csv
- report-004.csv
- report-005.csv
- report-006.csv
- report-007.csv
- report-008.csv
- report-009.csv
- report-010.csv
- report-011.csv
- report-012.csv
- report-013.csv
- report-014.csv
- report-015.csv
- report-016.csv
- report-017.csv
- report-018.csv
- report-019.csv
- report-020.csv
- report-021.csv
- report-022.csv
- report-023.csv
- report-024.csv
- report-025.csv
- report-026.csv
- report-027.csv
- report-028.csv
- report-029.csv
- report-030.csv
- report-031.csv
- report-032.csv
- report-033.csv
- report-034.csv
- report-035.csv
- report-036.csv
- report-037.csv
- report-038.csv
- report-039.csv
- report-040.csv
- report-041.csv
- report-042.csv
- report-043.csv
- report-044.csv
- report-045.csv
- report-046.csv
- report-047.csv
- report-048.csv
- report-049.csv
- report-050.csv
- report-051.csv
- report-052.csv
- report-053.csv
- report-054.csv
- report-055.csv
- report-056.csv
- report-057.csv
- report-058.csv
- report-059.csv
- report-060.csv
- report-061.csv
- report-062.csv
- report-063.csv
- report-064.csv
- report-065.csv
- report-066.csv
- report-067.csv
- report-068.csv
- report-069.csv
- report-070.csv
- report-071.csv
- report-072.csv
- report-073.csv
- report-074.csv
- report-075.csv
- report-076.csv
- report-077.csv
- report-078.csv
- report-079.csv
- report-080.csv
- report-081.csv
- report-082.csv
- report-083.csv
- report-084.csv
- report-085.csv
- report-086.csv
- report-087.csv
- report-088.csv
- report-089.csv
- report-090.csv
- report-091.csv
- report-092.csv
- report-093.csv
- report-094.csv
- report-095.csv
- report-096.csv
- report-097.csv
- report-098.csv
- report-099.csv
- report-100.csv
- report-101.csv
- report-102.csv
- report-103.csv
- report-104.csv
- report-105.csv
- report-106.csv
- report-107.csv
- report-108.csv
- report-109.csv
- report-110.csv
- report-111.csv
- report-112.csv
- report-113.csv
- report-114.csv
- report-115.csv
- report-116.csv
- report-117.csv
- report-118.csv
- report-119.csv
- report-120.csv
- report-121.csv
- report-122.csv
- report-123.csv
- report-124.csv
- report-125.csv
- report-126.csv
- report-127.csv
- report-128.csv
- report-129.csv
- report-130.csv
- report-131.csv
- report-132.csv
- report-133.csv
- report-134.csv
- report-135.csv
- report-136.csv
- report-137.csv
- report-138.csv
- report-139.csv
- report-140.csv
- report-141.csv
- report-142.csv
- report-143.csv
- report-144.csv
- report-145.csv
- report-146.csv
- report-147.csv
- report-148.csv
- report-149.csv
- report-150.csv
- report-151.csv
- report-152.csv
- report-153.csv
- report-154.csv
- report-155.csv
- report-156.csv
- report-157.csv
- report-158.csv
- report-159.csv
- report-160.csv
- report-161.csv
- report-162.csv
- report-163.csv
- report-164.csv
- report-165.csv
- report-166.csv
- report-167.csv
- report-168.csv
- report-169.csv
- report-170.csv
- report-171.csv
- report-172.csv
- report-173.csv
- report-174.csv
- report-175.csv
- report-176.csv
- report-177.csv
- report-178.csv
- report-179.csv
- report-180.csv
- report-181.csv
- report-182.csv
- report-183.csv
- report-184.csv
- report-185.csv
- report-186.csv
- report-187.csv
- report-188.csv
- report-189.csv
- report-190.csv
- report-191.csv
- report-192.csv
- report-193.csv
- report-194.csv
- report-195.csv
- report-196.csv
- report-197.csv
- report-198.csv
- report-199.csv
- report-200.csv
- report-201.csv
- report-202.csv
- report-203.csv
- report-204.csv
- report-205.csv
- report-206.csv
- report-207.csv
- report-208.csv
- report-209.csv
- report-210.csv
- report-211.csv
- report-212.csv
- report-213.csv
- report-214.csv
- report-215.csv
- report-216.csv
- report-217.csv
- report-218.csv
- report-219.csv
- report-220.csv
- report-221.csv
- report-222.csv
- report-223.csv
- report-224.csv
- report-225.csv
- report-226.csv
- report-227.csv
- report-228.csv
- report-229.csv
- report-230.csv
- report-231.csv
- report-232.csv
- report-233.csv
- report-234.csv
- report-235.csv
- report-236.csv
- report-237.csv
- report-238.csv
- report-239.csv
- report-240.csv
- report-241.csv
- report-242.csv
- report-243.csv
- report-244.csv
- report-245.csv
- report-246.csv
- report-247.csv
- report-248.csv
- report-249.csv
- report-250.csv
- report-251.csv
- report-252.csv
- report-253.csv
- report-254.csv
- report-255.csv
- report-256.csv
- report-257.csv
- report-258.csv
- report-259.csv
- report-260.csv
- report-261.csv
- report-262.csv
- report-263.csv
- report-264.csv
- report-265.csv
- report-266.csv
- report-267.csv
- report-268.csv
- report-269.csv
- report-270.csv
- report-271.csv
- report-272.csv
- report-273.csv
- report-274.csv
- report-275.csv
- report-276.csv
- report-277.csv
- report-278.csv
- report-279.csv
- report-280.csv
- report-281.csv
- report-282.csv
- report-283.csv
- report-284.csv
- report-285.csv
- report-286.csv
- report-287.csv
- report-288.csv
- report-289.csv
- report-290.csv
- report-291.csv
- report-292.csv
- report-293.csv
- report-294.csv
- report-295.csv
- report-296.csv
- report-297.csv
- report-298.csv
- report-299.csv
- report-300.csv
Motion
| Duration | Easing | |
|---|---|---|
| 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.
Collapsible
| Prop | Default | Type and description |
|---|---|---|
| defaultOpen | — | booleanStarts open when |
| open | — | booleanWhether the content shows, bound with |
| disabled | — | booleanDisables the trigger; the content stays as it is. |
| unmountOnHide | false | booleanUnmounts the content while closed, leaving an empty hidden panel. Off by default, so closed content stays in the page as |
| asChild | — | booleanRender the single child instead of a wrapper, merging the root's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Event | Payload and description |
|---|---|
| update:open | [value: boolean]Fires when the content opens or closes. |
| Slot | Scope and description |
|---|---|
| default | { open: boolean; }The trigger and the content. Receives |
CollapsibleTrigger
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRender the single child instead of a wrapper, merging the trigger's attributes, state and classes onto it. Wrap a |
| as | — | AsTag | ComponentThe element or component to render. A |
| Slot | Scope and description |
|---|---|
| default | {}The trigger's content. |
CollapsibleContent
| Prop | Default | Type and description |
|---|---|---|
| forceMount | — | booleanKeeps the content mounted and visible to animate it with an external library. |
| asChild | — | booleanRender the block inside as the panel itself, without the wrapper. |
| as | — | AsTag | ComponentThe element or component to render. |
| Event | Payload and description |
|---|---|
| contentFound | [(void | undefined)?]Fires when find in page matches text inside closed content and the browser opens it. |
| Slot | Scope and description |
|---|---|
| default | {}The content. |
Props
- defaultOpen
booleanStarts open whenv-model:openis not used.- open
booleanWhether the content shows, bound withv-model:open.- disabled
booleanDisables the trigger; the content stays as it is.- unmountOnHide
false booleanUnmounts the content while closed, leaving an empty hidden panel. Off by default, so closed content stays in the page ashidden="until-found"and find in page can open it.- asChild
booleanRender the single child instead of a wrapper, merging the root's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Emits
- update:open
[value: boolean]Fires when the content opens or closes.
Slots
- default
{ open: boolean; }The trigger and the content. Receivesopen.
Props
- asChild
booleanRender the single child instead of a wrapper, merging the trigger's attributes, state and classes onto it. Wrap aButtonthis way.- as
AsTag | ComponentThe element or component to render. A<button>by default.
Slots
- default
{}The trigger's content.
Props
- forceMount
booleanKeeps the content mounted and visible to animate it with an external library.- asChild
booleanRender the block inside as the panel itself, without the wrapper.classthen lands on the hidden panel again.- as
AsTag | ComponentThe element or component to render.
Emits
- contentFound
[(void | undefined)?]Fires when find in page matches text inside closed content and the browser opens it.
Slots
- default
{}The content.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| collapsible | data-state, data-disabled | The root. |
| collapsible-trigger | data-state, data-disabled, aria-expanded, aria-controls | The button, or the child it renders with as-child. |
| collapsible-content | data-state, data-disabled, hidden | The animated panel; hidden="until-found" while closed, or empty and hidden with unmount-on-hide. |
Keyboard
| Key | Action |
|---|---|
| Space | Opens or closes the content. |
| Enter | Opens or closes the content. |