Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Vue 3 debugging reference for reactivity issues, computed errors, watcher bugs, async failures, and SSR hydration problems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
reference/transition-group-move-animation-position-absolute.md
1---2title: TransitionGroup Move Animation Requires Position Absolute on Leaving Items3impact: HIGH4impactDescription: Without position absolute, surrounding items jump instead of smoothly animating5type: gotcha6tags: [vue3, transition-group, animation, move-transition, css, list-animation]7---89# TransitionGroup Move Animation Requires Position Absolute on Leaving Items1011**Impact: HIGH** - When items are added or removed from a list with `<TransitionGroup>`, surrounding items will instantly "jump" to their new positions instead of smoothly animating. This creates a jarring user experience and is one of the most common mistakes with list animations.1213The fix is to set `position: absolute` on the `leave-active` class so leaving items are taken out of the layout flow, allowing other items to smoothly animate into their new positions.1415## Task Checklist1617- [ ] Add `.list-move` class (or `.[name]-move`) for smooth repositioning18- [ ] Set `position: absolute` on `.list-leave-active` class19- [ ] Ensure the parent container has `position: relative` if needed20- [ ] Test with rapid add/remove operations to verify smooth animations2122**Incorrect - Items jump instead of moving:**23```vue24<template>25<TransitionGroup name="list" tag="ul">26<li v-for="item in items" :key="item.id">27{{ item.name }}28</li>29</TransitionGroup>30</template>3132<style>33/* INCOMPLETE: Missing move class and position absolute */34.list-enter-active,35.list-leave-active {36transition: all 0.5s ease;37}3839.list-enter-from,40.list-leave-to {41opacity: 0;42transform: translateX(30px);43}44</style>45```4647**Correct - Smooth move transitions:**48```vue49<template>50<TransitionGroup name="list" tag="ul">51<li v-for="item in items" :key="item.id">52{{ item.name }}53</li>54</TransitionGroup>55</template>5657<style>58/* CORRECT: Full set of classes for smooth animations */5960/* Apply transition to moving elements */61.list-move,62.list-enter-active,63.list-leave-active {64transition: all 0.5s ease;65}6667.list-enter-from,68.list-leave-to {69opacity: 0;70transform: translateX(30px);71}7273/* CRITICAL: Take leaving items out of layout flow */74.list-leave-active {75position: absolute;76}77</style>78```7980## Why This Works8182The FLIP animation technique Vue uses internally needs to calculate element positions. When an item leaves:83841. Without `position: absolute`: The leaving item still occupies space in the DOM852. Other items can't move until the leaving item is fully removed863. Result: Items snap to new positions after leave animation completes8788With `position: absolute`:89901. Leaving item is removed from normal layout flow immediately912. Other items can begin moving into the vacated space923. Result: Leaving animation and move animation happen simultaneously9394## Visual Diagram9596```97Without position: absolute:98[A] [B] [C] [D] <- Remove B99[A] [C] [D] <- B fading out, C/D waiting100[A] [C] [D] <- B gone, C/D jump instantly101102With position: absolute:103[A] [B] [C] [D] <- Remove B104[A][B][C] [D] <- B fading (absolute), C/D sliding left105[A] [C] [D] <- Smooth completion106```107108## Additional Considerations109110**Container Width:** When using `position: absolute`, items may need explicit widths:111112```css113.list-leave-active {114position: absolute;115width: 100%; /* Or specific width to maintain layout during leave */116}117```118119**Stacking Context:** Leaving items with `position: absolute` may stack above other elements:120121```css122.list-leave-active {123position: absolute;124z-index: -1; /* Optional: put behind other items */125}126```127128## Reference129- [Vue.js TransitionGroup Move Transitions](https://vuejs.org/guide/built-ins/transition-group.html#move-transitions)130- [FLIP Animation Technique](https://aerotwist.com/blog/flip-your-animations/)131