Bird
Raised Fist0
Vueframework~20 mins

TransitionGroup for lists in Vue - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of using <TransitionGroup> in Vue?
easy
A. To animate list items when they are added, removed, or moved
B. To fetch data asynchronously before rendering a list
C. To validate form inputs inside a list
D. To create a static list without any animations

Solution

  1. Step 1: Understand the role of <TransitionGroup>

    <TransitionGroup> is designed to animate changes in lists, such as adding or removing items.
  2. Step 2: Compare with other options

    Options A, C, and D describe unrelated tasks like data fetching, form validation, or static lists without animation.
  3. Final Answer:

    To animate list items when they are added, removed, or moved -> Option A
  4. Quick Check:

    TransitionGroup animates list changes = B [OK]
Hint: TransitionGroup is for smooth list animations only [OK]
Common Mistakes:
  • Thinking TransitionGroup fetches data
  • Confusing TransitionGroup with form validation
  • Assuming it creates static lists without animation
2. Which of the following is the correct way to specify the wrapper element for a <TransitionGroup> in Vue?
easy
A. <TransitionGroup element="ul">
B. <TransitionGroup wrapper="ul">
C. <TransitionGroup tag="ul">
D. <TransitionGroup container="ul">

Solution

  1. Step 1: Recall the correct attribute for wrapper element

    The tag attribute sets the HTML element used as the wrapper in <TransitionGroup>.
  2. Step 2: Verify the options

    Only <TransitionGroup tag="ul"> uses tag="ul", which is the correct syntax. Others use invalid attributes like wrapper, element, or container.
  3. Final Answer:

    <TransitionGroup tag="ul"> -> Option C
  4. Quick Check:

    Wrapper element uses tag attribute = C [OK]
Hint: Use tag="element" to set wrapper in TransitionGroup [OK]
Common Mistakes:
  • Using wrapper or element instead of tag
  • Omitting the tag attribute and expecting default
  • Confusing with other component props
3. Given this Vue template snippet, what will be the rendered output when the items array is ["A", "B"]?
<TransitionGroup tag="ul" name="fade">
  <li v-for="item in items" :key="item">{{ item }}</li>
</TransitionGroup>
medium
A.
  • A
  • B
with fade animation on changes
B.
  • A
  • B
  • with no animation
    C.
    • A
    • B
    but no animation because key is missing
    D. Syntax error due to missing key attribute

    Solution

    1. Step 1: Analyze the template structure

      The <TransitionGroup> uses tag="ul", so the wrapper is a <ul> element. The list items have unique keys from the item values.
    2. Step 2: Understand the output and animation

      The list renders as <ul><li>A</li><li>B</li></ul> and uses the "fade" CSS classes for animation on changes.
    3. Final Answer:

      <ul><li>A</li><li>B</li></ul> with fade animation on changes -> Option A
    4. Quick Check:

      Unique keys + tag="ul" = animated <ul> list [OK]
    Hint: Check tag and keys to predict output and animation [OK]
    Common Mistakes:
    • Assuming default wrapper is div instead of ul
    • Forgetting to add unique keys causing no animation
    • Thinking missing key causes syntax error
    4. Identify the error in this Vue code using <TransitionGroup>:
    <TransitionGroup tag="ul" name="slide">
      <li v-for="item in items">{{ item }}</li>
    </TransitionGroup>
    medium
    A. Incorrect tag attribute value; should be div
    B. Missing unique :key attribute on list items
    C. name attribute cannot be used with TransitionGroup
    D. v-for syntax is invalid

    Solution

    1. Step 1: Check for required attributes in v-for

      Each item in a list rendered by v-for inside <TransitionGroup> must have a unique :key attribute to track changes for animation.
    2. Step 2: Validate other attributes

      The tag="ul" and name="slide" are valid. The v-for syntax is correct.
    3. Final Answer:

      Missing unique :key attribute on list items -> Option B
    4. Quick Check:

      Unique keys required for TransitionGroup lists = A [OK]
    Hint: Always add :key on v-for items inside TransitionGroup [OK]
    Common Mistakes:
    • Ignoring the need for :key causing animation issues
    • Thinking tag must be div
    • Believing name attribute is invalid
    5. You want to animate a list of tasks with <TransitionGroup> using a custom CSS animation named "bounce". The tasks array may have duplicate names. Which approach ensures smooth animations without glitches?
    hard
    A. Do not use keys and rely on default behavior with name="bounce"
    B. Use :key="task" on list items and set name="bounce" on TransitionGroup
    C. Use :key="index" on list items and set name="bounce" on TransitionGroup
    D. Use :key="task + index" on list items and set name="bounce" on TransitionGroup

    Solution

    1. Step 1: Understand the importance of unique keys

      Keys must be unique to avoid animation glitches. Since tasks may have duplicate names, using just the task name as key is unsafe.
    2. Step 2: Combine task and index for uniqueness

      Concatenating task and index (e.g., task + index) creates unique keys even if names repeat, ensuring smooth animations.
    3. Step 3: Confirm usage of name attribute

      Setting name="bounce" on <TransitionGroup> applies the correct CSS animation classes.
    4. Final Answer:

      Use :key="task + index" on list items and set name="bounce" on TransitionGroup -> Option D
    5. Quick Check:

      Unique keys + name="bounce" = smooth animations [OK]
    Hint: Combine value and index for unique keys with animations [OK]
    Common Mistakes:
    • Using task name alone as key when duplicates exist
    • Using index alone causing wrong animation order
    • Skipping keys causing animation glitches
    Recommended

    Ready to prove it?

    Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

    10 questions~5 mineasy hard