Skip to content

Radix UI Collapsible Not Animating — Fix Smooth Open/Close

DodaTech Updated 2026-06-24 2 min read

In this fix, you'll learn how to animate Radix UI Collapsible transitions. This matters for smooth expand/collapse UX, and appears in filter panels and sidebars.

The Problem

The following code demonstrates the typical mistake:

<Collapsible>
  <CollapsibleTrigger>Toggle</CollapsibleTrigger>
  <CollapsibleContent>
    Hidden content here
  </CollapsibleContent>
</Collapsible>
// Content snaps open/closed without animation

The Fix

Here is the corrected version:

// Using Framer Motion AnimatePresence:
import { motion, AnimatePresence } from 'framer-motion';
<Collapsible>
  <CollapsibleTrigger>Toggle</CollapsibleTrigger>
  <AnimatePresence>
    <CollapsibleContent forceMount asChild>
      <motion.div
        initial={{ height: 0, opacity: 0 }}
        animate={{ height: 'auto', opacity: 1 }}
        exit={{ height: 0, opacity: 0 }}
        transition={{ duration: 0.2 }}
      >
        Hidden content here
      </motion.div>
    </CollapsibleContent>
  </AnimatePresence>
</Collapsible>
// Content animates smoothly on open and close

Prevention

  • Radix Collapsible doesn't animate by default — you must add animations yourself.
  • Use AnimatePresence from Framer Motion for mount/unmount animations.
  • Use forceMount to keep content in DOM for exit animations.
  • Use asChild on CollapsibleContent to pass animation props to the child element.
  • CSS transitions on max-height work but are less smooth than Framer Motion.

Common Mistakes with ui collapsible animate

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

These mistakes appear frequently in real-world RADIX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why doesn't Radix UI include animations?

Radix is a headless UI library — it provides behavior (accessibility, keyboard navigation) without styling. Animations are left to you with your animation library of choice.

What is forceMount used for?

forceMount keeps the CollapsibleContent in the DOM even when closed. This enables exit animations. Without it, the content is unmounted immediately when closed.

How do I animate with CSS transitions instead of Framer Motion?

Keep forceMount on CollapsibleContent, add a CSS class for open/closed states, and use transition on max-height and opacity. Set overflow: hidden on the container.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro