Auto Height

A container whose height glides to fit whatever is inside.

auto-height.tsx

Installation

1

Install the packages

npm install @prequelui/react motion

@prequelui/react reuses the primitive library your components already depend on.

2

Add the component

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/auto-height.json

npx shadcn@latest add https://animate.prequelui.terravidhal.me/r/auto-height.json

3

Turn on the motion

npx @prequelui/cli@latest animate auto-height

The CLI finds the component through components.json, swaps the import and removes the CSS animation classes that Motion replaces.

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

auto-height.tsx
import { AutoHeight } from "@/components/prequelui/effects/auto-height";

export default function Demo() {
  const [open, setOpen] = useState(false);
  return (
    <AutoHeight deps={[open]} className="w-[320px] overflow-hidden rounded-xl border">
      <p className="p-4 text-[13px] font-medium">Deployment summary</p>
      {open && <p className="px-4 pb-4 text-[13px] text-muted-foreground">…</p>}
    </AutoHeight>
  );
}
import { AutoHeight } from "@/components/prequelui/auto-height";

export function Variant() {
  return (
    <AutoHeight tempo={1.2}>
      …
    </AutoHeight>
  );
}

Animation

The container measures its child instead of guessing at a height. Every time the content, the font metrics or the parent box changes, a ResizeObserver reports the new size and the outer motion element springs to it with overflow hidden.

  • Height spring: stiffness 300, damping 30, bounce 0, restDelta 0.01.
  • The measured height is rounded to the device pixel ratio so text stays crisp.
  • The observer watches the child and the parent box, not only the root.
  • Reduced motion applies the new height instantly.
spring 300 / 30ResizeObserverDPR roundedinstant under reduced motion

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

AutoHeight

PropTypeDefault
childrenReactNode—
depsDependencyList[]
animateTargetAndTransition—
transitionTransitioncomponent spring or tween
asChildbooleanfalse
classNamestring—

useAutoHeight

PropTypeDefault
depsDependencyList[]
includeParentBoxbooleantrue
includeSelfBoxbooleanfalse

Built by Vidhal. The source is available on GitHub.

Last updated: 11/17/2026