The CSS transition effect is smooth when the accordion opens, but it does not have the same effect when

Currently, I am creating an accordion component that is supposed to have a smooth transition effect when opened and closed. However, while the transition works smoothly when the accordion opens, it seems to have some issues when it comes to closing.

I have tried experimenting with adding the transition value to different classes within the accordion, but so far, I have been unable to resolve the problem.

If anyone could offer some guidance or assistance in this matter, it would be greatly appreciated.

Here is a link to the Fiddle for reference.

JavaScript:

import React, { useEffect, useRef, useState } from "react";
import cx from "classnames";

import styles from "./accordion.module.scss";

export const Accordion = ({ bodyText, headerText }) => {
  // Rest of the JavaScript code remains the same

CSS

@import "../../colors.scss";

/* Customized CSS styling provided for the accordion component */
.accordion {
  // CSS styling for the accordion component
}

Answer №1

It seems like the animation is being cut short due to the component being unmounted right away. I believe there might be a better solution out there, so I recommend searching for something along the lines of "react unmount animation." Interactive Sandbox

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

Calculating the total number of clicks on a button using PHP

I am attempting to track the total number of clicks on a button by individual users, rather than combining all members' clicks. Each user's clicks on the button should be logged separately. I am struggling to determine the best approach for this ...

An issue occurred when trying to trigger a click event within a Blazor WebAssembly

While my dropdown menu option was working fine on a tablet-sized display, it suddenly stopped functioning after I published my project and ran the code in Visual Studio 2019 Preview version 16.10. I'm now seeing an error message in the browser console ...

To close the menu, simply tap on anywhere on the screen

Is there a way to modify a script so that it closes the menu when clicking on any part of the screen, not just on an 'li' element? $(function() { $('.drop-down-input').click(function() { $('.drop-down-input.selected').rem ...

Create a responsive design for a webpage that adjusts font size based on the dynamic type settings in iOS

Is there a way to ensure that my website's font size dynamically adjusts for iOS users? For example, if a user changes the font size in their iPhone settings (Settings > General > Accessibility > Larger Text), I want the webpage font size to ...

What is the best approach to breaking down attributes upon import according to the theme?

Hey there! Here's the thing - I have this file called <code>colors.ts:</p> export const black = '#0C0C0C'; export const blue = '#22618E'; Whenever I need to use a color, I import it like so: import {black} from 'S ...

persistently drifting towards the right despite the absence of direction

Why is the adminbox floating when no command is present? The fixed div center is not functioning properly .adminbox { width: 200px; height: 17px; margin-top: 20px; padding: 20px; font-size: 12px; ...

Position the Close Button within the CSS Cookie Consent Popup in perfect alignment

Having trouble aligning the close X button in my cookie consent popup to the center? I added a margin-top to adjust it, but I'm looking for a better solution. <div class="alert cookiealert" > By using our website you agree to our C ...

Utilizing dynamic meta tags in React JS with a PHP backend and Redux integration

Adding dynamic meta data like title, description, og_image, etc. in reactJs can be a bit complex. I've tried using the react-meta-tags package which changes the title and updates the meta data visible in my browser Inspector. However, when sharing on ...

Silhouette as the backdrop image

There is a span element that I am using in the following way - <span class="tick"></span> This creates a decorative "tick" for a checkbox. The CSS code used for this is - input[type="checkbox"] + span > span.tick { display: block; ...

Unleash the power of a module by exposing it to the global Window object using the dynamic

In my development process, I am utilizing webpack to bundle and manage my TypeScript modules. However, I am facing a challenge where I need certain modules or chunks to be accessible externally. Can anyone guide me on how to achieve this? Additional conte ...

Removing HTML tags from a React UL/LI component can be achieved by using regular

I am currently facing an issue with displaying a ul populated with lis in React on the DOM. The problem is that they are showing the HTML markup along with the content. https://i.sstatic.net/h4fIf.png For example: <strong>Wattage:</strong> 11 ...

Enhanced Search and Replace Techniques in HTML using jQuery and JavaScript

Although I have some experience with jQuery and Javascript, I am by no means an expert. I have been struggling to find a way to achieve my goal using minimal resources. Maybe you can assist me: This is what I am trying to accomplish: I would like to use ...

Is it possible to implement formvalidation.io in a React project that is using Materialize-css?

Can the formvalidation.io plugin be used with React and Materialize-css in a project? My project consists of multiple input components that may or may not be within a form. I want to utilize formvalidation for input validation. However, I am unable to find ...

What is the best way to implement a never-ending scrolling grid loader within a scrollable area using Codeigniter?

In my Codeigniter framework and bootstrap installation, I have multiple sub-pages. On one of these pages, I am attempting to implement an infinite scroll loader using a jQuery script from a tutorial found at gridScrollFx.js. Here is the JS file I am using: ...

Is it possible to replicate keystrokes using Selenium in a CodeMirror text editor?

There are numerous illustrations available that demonstrate how to input text using selenium by utilizing the following code: driver.execute_script('cm.setValue("text")'); While this method works, it does not align with the standard practices o ...

The alignment of columns in the fixed header table is off since it does not contain the necessary <thead> and <tbody> elements

On my page, I have three tables, with one of them containing a large amount of data. To make it easier to read, I decided to have a fixed header for the table. However, I am facing an issue where the columns in the thead (header) and tbody (body) are not a ...

What is the best way to create an HTML5 Range that gracefully degrades?

I want to incorporate the <input type='range' /> element from HTML5 for modern browsers and fallback to a <select /> if needed. Since I am working with Ruby-on-Rails, as a last resort, I could implement something similar to this on th ...

ReactJS Issue: Failure of Validation on Auto-Populated Form Field

I encountered an issue with the validation setup in my form. The validation checks the input values for "required", "max length", and "min length". Oddly, the validation only works for fields where the user manually types into the input field. I made some ...

Guide to configuring the API key within the Stampery API.JS script

Currently, I'm in the process of configuring Stampery but I'm facing difficulty locating where to insert the string API key within the API.JS file. The documentation mentions setting the STAMPERY_TOKEN as the API key, but I'm unsure how to p ...

In JavaScript, it is not possible to retrieve the maximum or minimum value of an array

Hey there! I'm having some trouble finding the minimum and maximum values in an array. Can you help me figure out what's going on with my code? var repeated, studentsArray = [], marksArray = []; while (repeated !== 'n' && r ...