Skip to main content

Collapse

The Collapse component provides animated show and hide transitions for content blocks.

It is based on Bootstrap 5 collapse behavior and uses react-transition-group internally to control transition states.

Import​

import { Collapse } from "@promethey/bsui";

Note

Badge inherits all utility props supported by the Prime component, including layout, spacing, typography, colors, borders, sizing, positioning, and other Bootstrap utility APIs.

Basic usage​

Use the open prop to control the visibility state.

Controlled state​

Collapse is a controlled component. The visibility state must be managed by the parent component.

Horizontal collapse​

Enable horizontal animation using the horizontal prop.

The component will animate the element width instead of height.

important

When using horizontal collapse, the child element must have an explicit width.

The width should be applied to the collapsing content element. Without it, the animation may not have a visible effect.

Mount On Enter​

Use mountOnEnter to delay rendering until the enter transition begins.

Unmount On Exit​

Use unmountOnExit to remove collapsed content from the DOM after the exit animation completes.

Transition duration​

Customize animation duration using the timeout prop.

The value is specified in milliseconds.

API​

PropTypeDefaultDescription
childrenReactNode—Content rendered inside the collapse container.
classNamestring | objectnullAdditional CSS classes applied to the root element.
styleobjectnullInline styles applied to the root element.
horizontalbooleanfalseEnables horizontal collapsing animation using width instead of height.
openbooleanfalseControls whether the content is expanded or collapsed.
mountOnEnterbooleanfalseDelays mounting the component until the enter transition begins.
unmountOnExitbooleanfalseRemoves the component from the DOM after the exit transition finishes.
appearbooleanfalseRuns the enter transition when the component is mounted initially.
enterbooleantrueEnables the enter transition when the component becomes visible.
exitbooleantrueEnables the exit transition when the component becomes hidden.
timeoutnumber350Transition duration in milliseconds.
addEndListener(node: HTMLElement, done: () => void) => voidnullCustom callback used to detect transition completion instead of timeout.
onEnter(node: HTMLElement, isAppearing: boolean) => voidnullCallback fired before the enter transition starts.
onEntering(node: HTMLElement, isAppearing: boolean) => voidnullCallback fired while the enter transition is running.
onEntered(node: HTMLElement, isAppearing: boolean) => voidnullCallback fired after the enter transition completes.
onExit(node: HTMLElement) => voidnullCallback fired before the exit transition starts.
onExiting(node: HTMLElement) => voidnullCallback fired while the exit transition is running.
onExited(node: HTMLElement) => voidnullCallback fired after the exit transition completes.