Vue3 Fundamentals · Built-in Components

Animate a list with TransitionGroup

Animating list changes with TransitionGroup

Animate a list with TransitionGroup

<Transition> handles one element. A list is different: items are added and removed, and each one needs its own enter and leave. That is what <TransitionGroup> is for.

Wrap the list in <TransitionGroup> and Vue animates every item as it joins or leaves. Unlike <Transition>, it does not require a single child — it expects a group.

<template>
  <TransitionGroup name="list" tag="ul">
    <li v-for="item in items" :key="item">{{ item }}</li>
  </TransitionGroup>
</template>

<TransitionGroup> renders no element of its own unless you ask. The tag prop tells it what to render around the items — here a ul. The name prop works like it does on <Transition>, prefixing the list-enter-* and list-leave-* classes.

Every child still needs a key, because Vue uses the key to track which item is entering or leaving.

The Test mounts your component and checks the items are wrapped in a transition group tagged ul. The starter renders a plain container, so the Test fails.

Challenge

The list is not animated. Wrap it in a transition group: export an App component from App.vue whose items render inside <TransitionGroup name="list" tag="ul">.

The Test mounts your component and checks the items sit in a transition group tagged ul. The starter renders a plain container, so the Test fails.

App.vue
<script setup>
import { ref } from 'vue';

const items = ref(['Alpha', 'Beta', 'Gamma']);
</script>

<template>
  <div>
    <li v-for="item in items" :key="item" data-test="item">{{ item }}</li>
  </div>
</template>

No test run yet

The Test is hidden. Run it to check the Challenge — you only see the result, never the test source.