Bird
Raised Fist0
Vueframework~10 mins

TransitionGroup for lists in Vue - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Vue TransitionGroup component correctly.

Vue
<script setup>
import { [1] } from 'vue'
</script>
Drag options to blanks, or click blank then click option'
ATransitionGroup
BTransition
CTeleport
DKeepAlive
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Transition instead of TransitionGroup.
Forgetting to import the component.
2fill in blank
medium

Complete the template to wrap the list items with the TransitionGroup component.

Vue
<template>
  <[1] tag="ul" name="fade">
    <li v-for="item in items" :key="item.id">{{ item.text }}</li>
  </[1]>
</template>
Drag options to blanks, or click blank then click option'
Atransition
Btransition-group
Cdiv
Dtemplate
Attempts:
3 left
💡 Hint
Common Mistakes
Using transition instead of transition-group.
Using a div or template tag instead.
3fill in blank
hard

Fix the error in the TransitionGroup usage by completing the missing attribute.

Vue
<template>
  <transition-group [1]="ul" name="slide">
    <li v-for="item in list" :key="item.id">{{ item.name }}</li>
  </transition-group>
</template>
Drag options to blanks, or click blank then click option'
Aclass
Btype
Cmode
Dtag
Attempts:
3 left
💡 Hint
Common Mistakes
Using type or mode instead of tag.
Omitting the tag attribute causing invalid HTML.
4fill in blank
hard

Fill both blanks to create a fade transition with correct CSS classes.

Vue
<style scoped>
.fade-[1] {
  opacity: 0;
  transition: opacity 0.5s ease;
}
.fade-[2] {
  opacity: 1;
}
</style>
Drag options to blanks, or click blank then click option'
Aleave-active
Benter-active
Center-to
Dleave-to
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing leave-active with enter-active.
Using leave-to instead of enter-to for fade-in.
5fill in blank
hard

Fill all three blanks to correctly bind the list and handle item removal with a key.

Vue
<template>
  <transition-group tag="ul" name="list">
    <li v-for="[1] in [2]" :key="[3].id">
      {{ [3].text }}
    </li>
  </transition-group>
</template>
Drag options to blanks, or click blank then click option'
Aitem
Bitems
Delement
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for loop and key.
Using a variable name not defined in the script.

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