0
0
Vueframework~20 mins

Transition component for animations in Vue - Practice Problems & Coding Challenges

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

Consider a Vue 3 component using the <Transition> component to wrap a single <div>. What is the visible effect when the wrapped 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>

<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter-from, .fade-leave-to {
  opacity: 0;
}
</style>
AThe <code>div</code> appears and disappears instantly 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 when shown and slides out when hidden.
DThe <code>div</code> blinks rapidly without a smooth transition.
Attempts:
2 left
💡 Hint

Think about how the CSS classes named with fade- affect opacity during enter and leave.

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

Vue's <Transition> component expects a single child element. Which code snippet correctly wraps multiple elements for transition?

A
&lt;Transition&gt;
  &lt;div&gt;
    &lt;div&gt;One&lt;/div&gt;
    &lt;div&gt;Two&lt;/div&gt;
  &lt;/div&gt;
&lt;/Transition&gt;
B
&lt;Transition&gt;
  &lt;div&gt;One&lt;/div&gt;
  &lt;div&gt;Two&lt;/div&gt;
&lt;/Transition&gt;
C
&lt;Transition&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&gt;
  &lt;span&gt;One&lt;/span&gt;
  &lt;span&gt;Two&lt;/span&gt;
&lt;/Transition&gt;
Attempts:
2 left
💡 Hint

Remember that <Transition> accepts only one root element. How can you group multiple elements without adding extra nodes?

state_output
advanced
2:00remaining
What is the value of isActive after the transition ends?

Given this Vue component using <Transition>, what will be the value of isActive after the leave transition finishes?

Vue
<template>
  <Transition @after-leave="handleAfterLeave">
    <div v-if="show">Content</div>
  </Transition>
  <button @click="show = false">Hide</button>
</template>

<script setup>
import { ref } from 'vue'
const show = ref(true)
const isActive = ref(true)
function handleAfterLeave() {
  isActive.value = false
}
</script>
Atrue
Bnull
Cundefined
Dfalse
Attempts:
2 left
💡 Hint

Look at the event @after-leave and what the handler does.

🔧 Debug
advanced
2:00remaining
Why does the transition not play when toggling visibility?

This Vue component uses <Transition> but the fade animation does not run when toggling show. What is the likely cause?

Vue
<template>
  <Transition name="fade">
    <div v-show="show">Hello</div>
  </Transition>
  <button @click="show = !show">Toggle</button>
</template>

<script setup>
import { ref } from 'vue'
const show = ref(true)
</script>

<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter-from, .fade-leave-to {
  opacity: 0;
}
</style>
AUsing <code>v-show</code> instead of <code>v-if</code> prevents the transition from triggering.
BThe CSS classes are missing the <code>opacity</code> property.
CThe <code>Transition</code> component requires a <code>mode</code> prop to work.
DThe <code>show</code> variable is not reactive.
Attempts:
2 left
💡 Hint

Think about how v-show and v-if differ in DOM behavior.

🧠 Conceptual
expert
3:00remaining
Which statement about <Transition> and accessibility is true?

When using Vue's <Transition> component for animations, which practice best supports accessibility?

AAlways use <code>aria-hidden</code> to hide elements during transitions to prevent screen reader confusion.
BDisable all animations for users with reduced motion preferences by ignoring <code>&lt;Transition&gt;</code>.
CEnsure that elements entering or leaving are properly focusable and update ARIA attributes as needed.
DUse <code>&lt;Transition&gt;</code> only on decorative elements to avoid accessibility issues.
Attempts:
2 left
💡 Hint

Think about how animations affect keyboard focus and screen readers.