Chapter 52: Vue TransitionGroup Component

Vue’s <TransitionGroup> component — one of the most satisfying and most frequently used animation tools in real Vue applications.

This is the specialized version of <Transition> that exists only for lists — that is, for content generated by v-for.

Without <TransitionGroup>, when items appear, disappear, or change order in a list, they just snap into or out of existence — no motion, no feeling of life.

With <TransitionGroup>, every single item can:

  • smoothly fade/slide/scale in when added
  • smoothly fade/slide/scale out when removed
  • gently slide to its new position when the list is reordered, filtered, or sorted

That last part — smooth sliding when order changes — is the killer feature that makes todo lists, kanban boards, search results, chat messages, product grids, notification lists, etc. feel modern and premium.

Quick Comparison: <Transition> vs <TransitionGroup>

Feature <Transition> <TransitionGroup> (for v-for)
Works with single element (v-if / v-show / dynamic :is) multiple elements generated by v-for
Animates position changes when order shifts? No Yes — items smoothly move to new positions
Requires :key on children? Recommended Mandatory — and must be unique & stable
Renders a wrapper element? No (unless you set tag) Yes — defaults to <span>, usually set tag=”ul”
Has special .move class? No Yes — this is what animates reordering
Most common real-world use-cases modals, alerts, dropdowns, tab content todo lists, cards, tables rows, messages, search results

Real, Complete Example – Animated Todo List (production style)

vue

The 6 Classes <TransitionGroup> Uses (Must Memorize)

Class suffix When it appears Typical CSS you write Duration
-enter-from Before item enters opacity: 0; transform: translateX(-40px);
-enter-active During enter animation transition: all 0.4s ease; active
-leave-to End state of leave animation opacity: 0; transform: translateX(40px);
-leave-active During leave animation transition: all 0.4s ease; position: absolute; active
-move When items reorder / shift position transition: transform 0.4s ease; active
-leave-active + absolute Prevents layout jump during removal position: absolute; width: 100%;

Why :key is mandatory here (and why index is dangerous)

Without correct :key:

  • Delete first item → Vue reuses DOM elements → animations look wrong
  • Reorder list → no .move animation → items jump instantly
  • Input focus lost when deleting above items

With correct :key=”todo.id”:

  • Vue knows exactly which item is being removed/added/moved
  • .move class triggers → items slide to new positions smoothly
  • Child component state (checkbox, input value) stays with the correct item

Pro Tips from Real Projects (Hyderabad 2026)

  • Always use unique, stable :key (database ID, UUID, Date.now() for local items)

  • Never use :key=”index” in dynamic lists — only okay for static lists

  • Use .move class for reordering animations — it’s what makes sortable lists feel premium

  • Add stagger delay for nicer effect:

    CSS
    vue
  • Combine with <KeepAlive> when list is inside tabs/router-view

  • Respect prefers-reduced-motion for accessibility

    CSS

Your mini homework:

  1. Build the todo list above
  2. Add stagger delay (each new item appears 80ms after previous)
  3. Add “Clear completed” button → watch multiple items leave smoothly
  4. Try removing :key → see how broken the animations & focus become

Any part confusing? Want full examples for:

  • Drag-and-drop sortable list with TransitionGroup?
  • Chat message list with staggered enter + avatars?
  • Animated filter/search results?
  • TransitionGroup inside <router-view>?

Just tell me — we’ll animate the next beautiful list together 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *