0
0
Vueframework~20 mins

TransitionGroup for lists in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vue TransitionGroup Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you remove the key attribute inside a TransitionGroup list?

Consider a Vue 3 component using <TransitionGroup> to animate a list of items. Each item has a unique key attribute. What is the visible effect if you remove the key attribute from the list items?

Vue
<template>
  <TransitionGroup name="fade" tag="ul">
    <li v-for="item in items" :key="item.id">{{ item.text }}</li>
  </TransitionGroup>
</template>
AThe list items animate correctly when added or removed.
BVue throws a runtime warning and animations may behave unpredictably.
CThe list renders but no animations occur, and no warnings are shown.
DThe component crashes with a TypeError.
Attempts:
2 left
💡 Hint

Think about how Vue tracks list items for transitions.

📝 Syntax
intermediate
2:00remaining
Which option correctly uses TransitionGroup with a custom tag and CSS classes?

Choose the correct Vue 3 syntax to wrap a list with TransitionGroup using a div tag and applying the CSS class list-container.

A
&lt;TransitionGroup tag="div" class:list-container&gt;
  &lt;div v-for="item in items" :key="item.id"&gt;{{ item.text }}&lt;/div&gt;
&lt;/TransitionGroup&gt;
B
&lt;TransitionGroup tag="div" :class="list-container"&gt;
  &lt;div v-for="item in items" :key="item.id"&gt;{{ item.text }}&lt;/div&gt;
&lt;/TransitionGroup&gt;
C
&lt;TransitionGroup tag="div" class="list-container"&gt;
  &lt;div v-for="item in items" :key="item.id"&gt;{{ item.text }}&lt;/div&gt;
&lt;/TransitionGroup&gt;
D
&lt;TransitionGroup tag="div" :class="['list-container']"&gt;
  &lt;div v-for="item in items" :key="item.id"&gt;{{ item.text }}&lt;/div&gt;
&lt;/TransitionGroup&gt;
Attempts:
2 left
💡 Hint

Remember how to bind static classes in Vue templates.

state_output
advanced
2:00remaining
What is the final rendered list after removing an item with TransitionGroup?

Given this Vue 3 component code, what is the final list rendered after clicking the 'Remove' button once?

Vue
<template>
  <TransitionGroup tag="ul" name="fade">
    <li v-for="item in items" :key="item.id">{{ item.text }}</li>
  </TransitionGroup>
  <button @click="removeFirst">Remove</button>
</template>

<script setup>
import { ref } from 'vue'
const items = ref([
  { id: 1, text: 'Apple' },
  { id: 2, text: 'Banana' },
  { id: 3, text: 'Cherry' }
])
function removeFirst() {
  items.value.shift()
}
</script>
A<ul><li>Banana</li><li>Cherry</li></ul>
B<ul><li>Apple</li><li>Cherry</li></ul>
C<ul><li>Apple</li><li>Banana</li></ul>
D<ul><li>Cherry</li></ul>
Attempts:
2 left
💡 Hint

What does shift() do to an array?

🔧 Debug
advanced
2:00remaining
Why does this TransitionGroup animation not run on list reorder?

In this Vue 3 code, the list items reorder but no animation runs. What is the cause?

Vue
<template>
  <TransitionGroup name="slide" tag="ul">
    <li v-for="item in items" :key="item.text">{{ item.text }}</li>
  </TransitionGroup>
  <button @click="reverse">Reverse</button>
</template>

<script setup>
import { ref } from 'vue'
const items = ref(['One', 'Two', 'Three'])
function reverse() {
  items.value = [...items.value].reverse()
}
</script>
AThe <code>tag</code> attribute must be <code>div</code> for animations to work.
BThe <code>TransitionGroup</code> requires a <code>mode</code> attribute to animate reorder.
CThe <code>reverse()</code> method mutates the array in place, breaking reactivity.
DUsing the item text as key causes Vue to reuse elements incorrectly, preventing animation.
Attempts:
2 left
💡 Hint

Keys must uniquely identify items even after reorder.

🧠 Conceptual
expert
3:00remaining
How does TransitionGroup differ from Transition in Vue 3?

Choose the best explanation of the difference between TransitionGroup and Transition components in Vue 3.

A<code>TransitionGroup</code> animates a list of elements with automatic move transitions; <code>Transition</code> animates a single element or component.
B<code>Transition</code> is used only for CSS animations; <code>TransitionGroup</code> is for JavaScript animations.
C<code>TransitionGroup</code> requires manual key management; <code>Transition</code> does not support keys.
D<code>Transition</code> can animate multiple elements simultaneously; <code>TransitionGroup</code> can animate only one.
Attempts:
2 left
💡 Hint

Think about single vs multiple elements animation.