The v-leave-active animation is functioning correctly, however, the v-enter-active animation is not working as expected on the <transition-group>

In my Vue 3 project, I have created a custom component called Accordion. The purpose of this component is to toggle the display of its content when a button (created using a div instead of a <button> tag) is clicked. The Accordion utilizes a <slot> to receive incoming elements.

The <slot> is contained within a <transition-group>, and the template for the Accordion looks like this:

<template>
  <div id='accordion'>
    <div :id="['accordion', id, 'collapsible-wrapper'].join('-')" class="collapsible-wrapper">
      <div id='toggle-content' :class="(collapsed ? 'icon-plus green flip expand-content-button': 'icon-minus green flip expand-content-button')" @click="collapsed = !collapsed">
      </div>
    </div>
    <transition-group name="accordion">
      <slot v-if="!collapsed"></slot>
    </transition-group>
  </div>
</template>

When the 'toggle-content' div is clicked, the content in the <slot> should be displayed with a short animation. However, the animation before displaying the content is not functioning properly. Currently, the content does show up after clicking the button though.

Here is the CSS code for the animation:

.accordion-enter-active{
  transition: all 0.3s ease-out;
}
.accordion-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}
.accordion-enter-from,
.accordion-leave-to {
  transform: translateX(20px);
  opacity: 0;
} 

This is how I am implementing the Accordion component:

<Accordion :id="1">
  <div class="wrapper1-for-contents">
    <div>Some Stuff here</div>
    <div>Some more stuff here</div>
  </div>
  <div class="wrapper2-for-contents">
    <div>Some Stuff here</div>
    <div>Some more stuff here</div>
  </div>
</Accordion>

By using <transition> instead of <transition-group>, the animation prior to displaying the content works correctly. However, only the content inside the first div with the class "wrapper1-for-contents" appears, while the content inside the second div remains hidden.

I came across a similar issue on Stack Overflow but the provided solution did not solve my problem.

If anyone can offer assistance or guidance on what might be causing this issue, it would be greatly appreciated.

Answer №1

For an interesting effect, consider including the 'appear' attribute in the <transition-group> element

<transition-group name="accordion" appear>

Answer №2

After some troubleshooting, I managed to resolve the problem even though the reason behind it eludes me. Interestingly, enclosing the content of my accordion component within a div (prior to assigning the id="1") seemed to fix the animation issue completely.

My apologies for the delayed update.

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

Why does async return an empty array the first time it is used?

I'm currently developing a JavaScript application using Node.js. I have been experimenting with the async/await function. After running the code snippet below, I noticed that the first time I send a GET request, I receive an empty array. However, if ...

Tips for showcasing a drop-down menu using Jquery

I am currently utilizing jQuery to showcase a drop-down menu. It is successfully working for a single menu and displaying the appropriate drop-down. However, when I attempt to use more than one menu, it displays all of the drop-down menus simultaneously. I ...

Customize hover effects in tailwind css with dynamic values

I am trying to customize the text color on hover based on different category names using tailwind CSS. In my configuration, I have assigned a specific color code for each category like this : tailwind.config.js theme: { extend: { } }, co ...

Ways to access file attributes and transfer a file in ionic 4?

I am facing an issue while attempting to transfer a file from my mobile device to Google bucket using Ionic 4. Although I can successfully upload the file, I am struggling to extract its properties from the file object. Below is the method I am using: as ...

Querying Mongodb with current time parameters

I'm attempting to create a mongo query that retrieves all active listings based on the current date { $and: [ { start_time: { $lte: { $currentDate: { $type: "date" } } } } ...

What is the best way to reset Owl Carousel following an ajax request?

I am attempting to reinitialize the owl carousel following a successful ajax call. The ajax call will update the data while retaining the same view. I am encountering an issue where the carousel structure in the view does not reinitialize, and I am unsure ...

Tips for storing and retrieving high scores in a JavaScript game

I've just finished creating a JavaScript snake game and now I'd like to add a "scores" option that displays the top 10 players along with their names and scores. My initial plan was to create an object containing the player's name and score ...

Is there a way for me to send a URL request from my website to a different server using PHP?

I am looking to initiate a request from my website to my server using a specific IP address. From there, I need the server to send another request to a different server and then display the response on the webpage. Can anyone provide guidance on how to ...

How to generate error code 1006 for WebSockets using JavaScript

Is there a reliable method to generate the close code 1006 consistently in websockets? I am attempting to replicate this situation in a JavaScript client. ...

What is the best way to organize divs in a grid layout that adapts to different screen sizes, similar to the style

Is there a way to align multiple elements of varying heights against the top of a container, similar to what is seen on Wolfram's homepage? I noticed that they used a lot of JavaScript and absolute positioning in their code, but I'm wondering if ...

Browser unable to store cookies, unlike postman where cookies can be set

I've scoured the web, but I just can't seem to get it to work. I meticulously followed the steps outlined in this blog post. This snippet handles sending my cookie on the server: //after user authentication export const logInUser = async (req, r ...

Conceal the title attribute when hovering over a link using javascript/jquery

I have implemented the title attribute for all my links, but I want it to be hidden during mouse hover while still accessible to screen readers. var linkElements = document.getElementsByTagName('a'); for (var index = 0; index < linkElements. ...

If a file exists in Node.js, use fs.ensureDir to replace it with a directory

If I were to save something in a file at /group1/sub1 [file] and then use fs.ensureDir on /group1/sub1/subsub1/test [dir] Node will throw an error: Error: ENOTDIR: not a directory, halting the process. Is there a way to convert the file into a directory ...

Delete specific rows by clicking a button in AngularJS

I have a table with checkboxes for each row and I am trying remove the selected rows when a button is clicked. The selected row indexes are stored in an array using ng-change, but I cannot figure out how to delete them all at once with a single button clic ...

Incapable of stacking one canvas on top of another

I'm new to javascript and looking for help with positioning a canvas element behind another. The code I have may be a bit messy, so any assistance is greatly appreciated. My goal is to have the canvas named "myCanvas" appear behind "coinAnimation". Th ...

Initializing MongoDB server instance created by NodeJS using npm installation

I've recently installed mongodb on my OSX machine by running the command npm install mongodb in the myapp/node_modules directory while using node.js. However, I'm a bit confused because the mongodb official documentation states that to start mong ...

Having trouble accessing the selected item in the $scope when using ng-options inside ng-repeat?

I am looking to achieve the following: I have an array called 'all' that contains all possible items. I want to create a subset of that array and store it in 'subset': JavaScript (js.js): var app = angular.module('myApp', [ ...

When trying to locate an item in an array within a VUE application, it may result in

I've got this code snippet that successfully finds the item details in an array: var findGroupId = medias.find(medias => medias.group_name === this.groupName) The medias variable is an array. When I run console.log(findGroupId), I get this result ...

Dynamic columns not rendering correctly when using smart-table with ng-repeat

html <table st-table="ApplicationData.displayedCollection" class="table table-striped" st-safe-src="ApplicationData.source"> <thead> <tr ng-repeat="col in ApplicationData.columns"> <td st-sort="{{col.name}}"> ...

What is the method for locating a particular link within a concealed row of a table solely based on linkText/linkName, without resorting to css-selectors or xpath?

Looking for a unique link in a dynamic table Each row in the table expands to reveal more information when clicked. However, since the rows and IDs are constantly changing, finding a specific link by its text is challenging without using xpath. Attempts ...