All components
MotionHeight
Height that follows its content: collapse, expand and content changes.
WebReact NativeContent and size
Try it
Shortest usage
Details.jsx<button onClick={() => setOpen(!open)}>Details</button>
<MotionHeight open={open}>
<Answer />
</MotionHeight>
What it handles for you
- Animates to the content's real height, measured for you.
- Follows the content when it grows or shrinks while open.
- Starts from the height on screen, even in the middle of a change.
- Resizing the page snaps instead of lagging behind the new width.
- Closed content stays mounted but hidden and inert, so its state is kept.
Use it for
- Answers in a FAQ.
- A group of settings that opens.
- A list whose total height should animate (wrap
MotionList).
Props
| Prop | Type | Default | Description |
|---|
open | boolean | true | false collapses to zero height; the content stays mounted but hidden and inert. |
|---|
children | ReactNode | | The content. |
|---|
as | element | 'div' | The element to render. |
|---|
transition | Transition | spring | A timing curve { duration, easing } or a spring { tempo: 'spring', spring }. Springs keep their momentum when interrupted. |
|---|
onMotionComplete | (open) => void | | Runs with open once the height has settled. |
|---|
Other props go to the rendered element, so className, style and event handlers work as usual.