Collapsible
An interactive component that can be expanded or collapsed.
An interactive component that can be expanded or collapsed.
You can use CSS animations to create smooth transitions for opening and closing the Collapsible content.
Utilize the data-state
attribute in combination with the --height
CSS variable to animate the open and closed states.
@keyframes slideDown {
from { height: 0; }
to { height: var(--height); }
}
@keyframes slideUp {
from { height: var(--height); }
to { height: 0; }
}
[data-scope='accordion'][data-part='item-content'][data-state='open'] {
animation: slideDown 250ms;
}
[data-scope='accordion'][data-part='item-content'][data-state='closed'] {
animation: slideUp 200ms;
}
Learn how to use the Collapsible
component in your project. Let’s examine
the most basic example:
import { Collapsible } from '@ark-ui/react'
export const Basic = () => (
<Collapsible.Root>
<Collapsible.Trigger>Toggle</Collapsible.Trigger>
<Collapsible.Content>Content</Collapsible.Content>
</Collapsible.Root>
)
import { Collapsible } from '@ark-ui/solid'
export const Basic = () => (
<Collapsible.Root>
<Collapsible.Trigger>Toggle</Collapsible.Trigger>
<Collapsible.Content>Content</Collapsible.Content>
</Collapsible.Root>
)
<script setup lang="ts">
import { Collapsible } from '@ark-ui/vue'
</script>
<template>
<Collapsible.Root>
<Collapsible.Trigger>Toggle</Collapsible.Trigger>
<Collapsible.Content>Content</Collapsible.Content>
</Collapsible.Root>
</template>
You can listen for the onExitComplete
event to know when the Collapsible.Content
is no longer visible:
Story not found
Story not found
Story not found
To delay the mounting of the Collapsible.Content
, use the lazyMount
prop:
Story not found
Story not found
Story not found
To remove the Collapsible.Content
from the DOM when it is not visible, use the
unmountOnExit
prop:
Story not found
Story not found
Story not found
Both lazyMount
and unmountOnExit
can be combined to ensure that the component is
mounted only when the Collapsible
is expanded and unmounted when it is collapsed:
Story not found
Story not found
Story not found
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean | |
defaultOpen The initial open state of the collapsible when it is first rendered.
Use when you do not need to control its open state. | boolean | |
disabled Whether the collapsible is disabled | boolean | |
id The unique identifier of the machine. | string | |
ids The ids of the elements in the collapsible. Useful for composition. | Partial<{ root: string; content: string; trigger: string }> | |
lazyMount Whether to enable lazy mounting | boolean | false |
onExitComplete Function called when the animation ends in the closed state. | () => void | |
onOpenChange Function called when the popup is opened | (details: OpenChangeDetails) => void | |
open Whether the collapsible is open | boolean | |
unmountOnExit Whether to unmount on exit. | boolean | false |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Previous
ClipboardNext
Color Picker