Skip to content

Collapsible

A component that expands and collapses long content areas.

Collapsible is used to show a preview of long content and let users expand it when needed.

Collapsible renders a built-in trigger button below the content. Use collapsedHeight to set how many pixels of content are visible when collapsed.

import { Collapsible, Flex, Text, ThemeSpace } from "@caspeco/casper-ui-library";
export default function Demo() {
return (
<Collapsible collapsedHeight={80} defaultExpanded={false}>
<Flex direction="column" gap={ThemeSpace.Medium}>
<Text>
Casper UI Collapsible lets you show long content in a compact layout and expand it when needed. It
is useful for descriptions, terms, and informational blocks where full text is optional at first
glance.
</Text>
<Text>
The collapsedHeight prop controls how many pixels of content remain visible in the collapsed state.
</Text>
<Text>
When the content is shorter than collapsedHeight, the trigger button is hidden automatically and the
content stays fully visible.
</Text>
</Flex>
</Collapsible>
);
}

If the content is shorter than collapsedHeight, the component stays fully expanded and the trigger button is hidden.

The trigger is exposed as a button control and updates aria-expanded based on visibility.