<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?
<template> <transition name="fade"> <div v-if="show">Hello</div> </transition> </template> <script setup> import { ref } from 'vue' const show = ref(true) </script>
Think about what the name attribute on <transition> does and how Vue applies CSS classes.
The <transition> component applies CSS classes with the prefix fade during the element's enter and leave phases. This triggers CSS transitions that cause the element to fade in and out smoothly.
<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?
Remember that <transition> requires a single root element, but <transition-group> can handle multiple siblings.
Option D wraps multiple elements inside a single <div>, satisfying the single child requirement of <transition>. Option D uses <transition-group>, which is for lists, not <transition>.
When an element enters using a <transition name="fade">, which sequence of CSS classes does Vue apply?
Vue applies classes in a specific order to trigger CSS transitions properly.
Vue first applies fade-enter-from and fade-enter-active, then switches fade-enter-from to fade-enter-to to start the transition.
Given this code, the element fades in but disappears instantly without fade on leave. What is the cause?
<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>
Check the opacity values for leave classes carefully.
The leave transition requires fade-leave-from to start at opacity 1 and fade-leave-to to end at opacity 0. The code has them reversed, so the fade out does not animate properly.
<transition> component handle accessibility during animations?When using <transition> to animate elements entering and leaving, what should you consider to maintain accessibility?
Think about how screen readers detect presence of elements and timing of DOM removal.
Vue's <transition> delays removing elements from the DOM until after the leave animation finishes. This ensures screen readers detect the element's presence correctly during the animation.