A container that animates its height to fit its content whenever it changes.
Installation
Usage
<script setup lang="ts">
import { AutoHeight } from '@animate-ui/vue/primitives/effects/auto-height';
defineProps<{ expanded: boolean }>();
</script>
<template>
<AutoHeight :deps="[expanded]">
<LongContent v-if="expanded" />
<ShortContent v-else />
</AutoHeight>
</template>The content is measured with a ResizeObserver, so the height also follows changes deps doesn't know about (fonts loading, images, a resized window). deps re-measures right away when your state changes.
Animation
- The height springs to the content's height (stiffness 300, damping 30, no bounce), clipping the content while it moves.
- With
box-sizing: border-box(Tailwind's default), the container's padding and border are included in the measured height. <AnimateUIProvider :tempo>paces the default spring.- Under reduced motion, the height changes at once.
API Reference
AutoHeight
| Prop | Type | Default |
|---|---|---|
as-child? | boolean | false |
deps? | unknown[] | [] |
transition? | Transition | { type: 'spring', stiffness: 300, damping: 30, bounce: 0, restDelta: 0.01 } |
animate? | TargetAndTransition | LegacyAnimationControls | - |
#default | slot | - |
...props? | Omit<HTMLMotionProps<'div'>, 'animate'> | - |