0
0
Vueframework~20 mins

Transition component basics in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Transition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a Vue <transition> wraps a single element?

Consider a Vue component using the <transition> wrapper around a single <div>. What is the visible effect when the element is conditionally rendered?

Vue
<template>
  <transition name="fade">
    <div v-if="show">Hello</div>
  </transition>
</template>

<script setup>
import { ref } from 'vue'
const show = ref(true)
</script>
AThe <code>div</code> instantly appears and disappears without animation.
BThe <code>div</code> fades in and out smoothly when <code>show</code> changes.
CThe <code>div</code> slides in from the left but does not fade.
DThe <code>div</code> remains visible and does not respond to <code>show</code>.
Attempts:
2 left
💡 Hint

Think about what the name attribute on <transition> does and how Vue applies CSS classes.

📝 Syntax
intermediate
2:00remaining
Which option correctly uses the <transition> component with multiple elements?

Vue's <transition> component only accepts one child element. How do you correctly wrap multiple elements to animate them together?

A
&lt;transition name="slide"&gt;
  &lt;div&gt;One&lt;/div&gt;
  &lt;div&gt;Two&lt;/div&gt;
&lt;/transition&gt;
B
&lt;transition-group name="slide"&gt;
  &lt;div&gt;One&lt;/div&gt;
  &lt;div&gt;Two&lt;/div&gt;
&lt;/transition-group&gt;
C
&lt;transition name="slide"&gt;
  &lt;template&gt;
    &lt;div&gt;One&lt;/div&gt;
    &lt;div&gt;Two&lt;/div&gt;
  &lt;/template&gt;
&lt;/transition&gt;
D
&lt;transition name="slide"&gt;
  &lt;div&gt;
    &lt;div&gt;One&lt;/div&gt;
    &lt;div&gt;Two&lt;/div&gt;
  &lt;/div&gt;
&lt;/transition&gt;
Attempts:
2 left
💡 Hint

Remember that <transition> requires a single root element, but <transition-group> can handle multiple siblings.

state_output
advanced
2:00remaining
What is the class sequence applied during a Vue transition?

When an element enters using a <transition name="fade">, which sequence of CSS classes does Vue apply?

Afade-enter-from → fade-enter-active → fade-enter-to
Bfade-enter → fade-enter-to → fade-enter-active
Cfade-enter-active → fade-enter-from → fade-enter-to
Dfade-enter-from → fade-enter-to → fade-enter-active
Attempts:
2 left
💡 Hint

Vue applies classes in a specific order to trigger CSS transitions properly.

🔧 Debug
advanced
2:00remaining
Why does this Vue transition not animate on leave?

Given this code, the element fades in but disappears instantly without fade on leave. What is the cause?

Vue
<template>
  <transition name="fade">
    <div v-if="show">Bye</div>
  </transition>
</template>

<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter-from, .fade-leave-from {
  opacity: 0;
}
.fade-enter-to, .fade-leave-to {
  opacity: 1;
}
</style>
AThe <code>v-if</code> directive is not reactive, so leave animation is skipped.
BThe <code>transition</code> property is missing on <code>fade-leave-active</code>.
CThe <code>fade-leave-from</code> and <code>fade-leave-to</code> classes are reversed in opacity values.
DThe <code>fade-leave-active</code> class is missing from the CSS.
Attempts:
2 left
💡 Hint

Check the opacity values for leave classes carefully.

🧠 Conceptual
expert
3:00remaining
How does Vue's <transition> component handle accessibility during animations?

When using <transition> to animate elements entering and leaving, what should you consider to maintain accessibility?

AEnsure elements are removed from the DOM only after animations finish to keep screen readers updated.
BAdd <code>aria-hidden="true"</code> to elements during transitions to hide them from screen readers.
CUse <code>tabindex="-1"</code> on animated elements to prevent keyboard focus during animation.
DDisable all animations for users with reduced motion preferences by detecting CSS media queries.
Attempts:
2 left
💡 Hint

Think about how screen readers detect presence of elements and timing of DOM removal.