Issues encountered when using Vue Transition in conjunction with v-autocomplete

Attempting to conditionally display or hide a selection text field using Vue's Transition feature, but experiencing an issue where the text field appears and disappears without any transition effect.

<template>
  <Transition
    v-if="isActive"
    name="fade"
  >
    <v-autocomplete
      :items="[1,2,3]"
    ></v-autocomplete>
  </Transition>
</template>

<script setup>
import { ref } from 'vue'
const isActive = ref(false); // This will be toggled in a different location of the code
</script>


<style scoped>
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>

Various attempts have been made, such as placing the v-if on the v-autocomplete component instead of the Transition, yet the desired behavior is not achieved. An example can be seen on Vuetify Playground

Inquiring about what could be going wrong with my approach. If achieving this behavior through Transition is not viable, seeking alternative methods to attain the same outcome.

Answer №1

You might want to include the v-if in the first child element, not in the Transition component.

<Transition name="fade">
  <v-autocomplete
    v-if="isActive"
    :items="[1,2,3]"
  ></v-autocomplete>
</Transition>

const { createApp, ref } = Vue
const { createVuetify } = Vuetify

const vuetify = createVuetify()

const app = createApp({
  setup() {
    const isActive = ref(true)
    
    return { isActive }
  }
})
app.use(vuetify).mount('#app')
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ff9faeafbe6e9f6cfbca1bca1be">[email protected]</a>/dist/vuetify.min.css">

<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="addbd8c8ed9e839e8399">[email protected]</a>/dist/vue.global.prod.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7a1a2b2a3beb1ae97e4f9e4f9e6">[email protected]</a>/dist/vuetify.min.js"></script>

<div id="app">
  <v-btn @click="isActive = !isActive">Toggle</v-btn>
  <Transition name="fade">
    <v-autocomplete
      v-if="isActive"
      :items="[1,2,3]"
    ></v-autocomplete>
  </Transition>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The 'with()' function in Eloquent is returning a null value

I am currently facing an issue with a simple relationship setup between two models: User and Prescription. A user can have multiple prescriptions associated with them. However, in the PrescriptionsController, when I attempt to retrieve the user that the pr ...

Styling images and text in CSS within a jQuery UI autocomplete widget

I am currently using an autocomplete widget that displays text along with images. The results I have right now are not meeting my requirements. I want to customize the appearance of my results so that the words 'test' and either 'Federico&a ...

There seems to be a problem with the background repeating space in the CSS

body { background-image: url("https://source.unsplash.com/user/c_v_r/100x100"); background-size: 100px; background-repeat: space; } <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA- ...

Autofill functions may not be compatible with input fields generated using JavaScript

Having trouble with browsers not using autocomplete in login overlays generated with JavaScript? It can be really annoying. Any suggestions on how to fix this issue? Should I create a hidden form within the original HTML and then move it into the overlay? ...

Accessing objects in an array in Vue 3 may pose a challenge

Struggling to access individual values from an Array fetched from Spring Boot in Vue. The issue is, I can only display the entire Array instead of looping through and showing single attributes from 0 to 3 per item like I did with the user object. The erro ...

How can the value be passed as an Array to the data in Vue.js?

Passing the object value as props into my "data" studentId within the form is a key aspect of my project. data() { return { form: new Form({ studentId: [] }) }; }, In the method, the initial values for classlists are set to ...

What steps are involved in incorporating dynamic pagination in PHP using this particular snippet of code?

I am looking for a way to display a list of numbers from 1 to 1000 in a single line with the ability to scroll. However, I need to exclude both "Prev" and "1" from this list. How can I achieve this? Below is the code snippet that I currently have: echo ...

Prioritizing nth child over the first child

I have a situation where I need to maintain 3 different styles in a patterned design without altering the classes on the HTML side. I have been attempting to achieve this using nth-child selectors. However, I am facing an issue where my first class is bein ...

What methods can be used to construct components using smaller foundational components as a base?

Is there a more elegant approach to constructing larger components from smaller base components that encompass common functionalities, akin to an interface in the OOP realm? I'm experimenting with this concept, but it feels somewhat inelegant. Repor ...

Switch up the default font in your Nuxt 3 and Vuetify 3 project

I've been doing a lot of searching on Google, but I can't seem to find the solution. It seems like the challenge might be that the Nuxt 3 + Vuetify 3 combination isn't widely used yet? My current task is to implement a custom default font. ...

Developing a dynamic web application using the Django framework along with the Vue.js library and Highcharts for

I am currently working on a data visualization web app using Django, Highcharts, and JQuery. I have recently transitioned from JQuery to Vue JS and I am struggling with fetching JSON data from a specific URL. Below is the code snippet: Template <!doc ...

Is it feasible to decrease the lateral margins of Bootstrap's container without the need for custom CSS? If so, what is the method?

My web page includes several screenshots to illustrate the issue I am facing. One of my challenges is the scroll bar below the table, which I find displeasing. In an attempt to resolve this, I decided to adjust the lateral margins slightly. Here's a s ...

Steps for positioning a div with list items to match the height of its parent container

I've been grappling with this problem for a long time now. Within the parent div "wrapper," there is a child div called "sidebar-wrapper" that contains an ul with li elements. I'm trying to make the height of "sidebar-wrapper" adjust to match t ...

Encountered a complication during the compilation process using Laravel Mix and Vue framework

I have successfully integrated Laravel 8 with Vue Js in the past, but recently encountered an error when starting a new project with both frameworks. Here are the commands I used: Laravel v8.26.1 (PHP v7.4.3) composer create-project --prefer-dist laravel ...

Is it necessary for Vue single file components (.vue files) to use `export default` or is it possible to use named exports instead?

export default may no longer be the recommended way to export modules, as discussed in these resources: After changing my Vue components from this: <script lang="ts"> 'use strict'; import {store} from '../../data/store' ...

Strategies for decreasing padding or margin in Bootstrap without removing it

I am currently facing a dilemma with the grid system. Although it is supposed to be easy, I am struggling at the moment. Let's consider that I need to correctly implement the Bootstrap grid for this example: https://i.stack.imgur.com/33vse.png Initi ...

Setting a button next to an input field in Bootstrap 4: A step-by-step guide

I have a form group with a label and input field. My goal is to position the button next to the input field on the same line. Here's an example of my code: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstra ...

Adjust the overall size of the CSS baseball field

Attempting to adjust the size of the baseball field proved challenging, as it wasn't a simple task. Is there a way to achieve this effectively? Thanks, HTML - is using DIV the only method for resizing? I couldn't find a way to resize everything a ...

HTML5 template design clashes with Smarty framework

I've been working with a simple pattern like this: <input type="text" pattern="[a-z]{2}" required ../> However, it never seems to be valid. The pattern doesn't seem to work as expected. I have only tested it in Firefox so far. Is there ...

Issue with the demo code for Vue Stripe Checkout

As I delve into the world of Vue-Stripe-Checkout, I encountered a snag right from the start with the demo code provided. The issue arises when utilizing the Vue Stripe Elements component. Has anyone else experienced this problem? There are no errors displa ...