Having trouble with transitions in CSS using React.js?

I am facing an issue with a CSS property transition that is set to height 3s, but it's not working as expected. The context is within a React.js application.

Despite my attempts, there is no smooth transition effect on the height when triggered.

Here is a snippet of the JSX code:

function Form({showPopup}){
  const [height, setHeight] = useState("400px")
    function proceedWithOtp(message){
      setHeight("300px")
      setForm(<OtpForm message={message}/>)
    }
    const [form, setForm] = useState(<RegisterForm showPopup={showPopup} proceedWithOtp={proceedWithOtp}/>)

    return (
      // This system is used so that height animation can work
      <div className="register-form" style={{
        height: height
      }}>
        {form}
      </div>
    )
}

CSS Styles:

.Register .register-form form {
    width: 350px;
    padding: 25px;
    border-radius: 25px;
}

.Register .register-form {
    display: flex;
    justify-content: center;
    align-items: center;
    transition: height 5s;
}

.Register .register-form form * {
    padding: 5px;
}

The RegisterForm component returns the following form structure:

        <form onSubmit={handleSubmit}  className="bg-white text-dark email-form">
            <h1 className="text-center font-hagrid">Register</h1>
            <br />
            <div className="mb-3">
    ...
...
...

The OtpForm component returns:

 <form className="bg-white text-dark otp-form" >
  <p className="text-center">{message}</p>
 ...
...
...

<button disabled={false} type="submit"  className="btn btn-primary btn-submit text-dark">{"Submit"}</button> 
</form>

This register form should have a fixed height with animated transitions applied through CSS, however, the animations are not functioning correctly. I'm looking for suggestions on how to troubleshoot and resolve this issue.

Answer №1

Animating the height property in CSS can be tricky when it's set to 'auto' (source). One workaround is to adjust the height using JavaScript and the scrollHeight property, or you can explore various solutions shared here.

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

Using React to showcase an array of objects in a table with row spanning

I'm facing a challenge with displaying adjustedAmount, paidAmount, and cost type in a table where one row is divided into multiple costs. Can someone help me figure out how to do this? Below is the object I need to work with: const datdfa = [ { ind ...

What is the best way to center align and add an icon to the header in Ionic?

How can I center align an "ion-ios-arrow-up" icon in the header of my Ionic app, similar to the concept shown below? This is my HTML template: <ion-view cache-view="false" view-title="Historical HPP"> <ion-nav-bar class="nav-title-slide-ios7 ...

What is the process for importing a node module in React-Kotlin?

After creating my app using the create-react-kotlin-app command, it loaded successfully in Chrome. I then installed the React Material UI package via NPM without any issues. However, I am now facing the challenge of incorporating the Material UI module int ...

Randomizing the JSON loop on every page refresh

Having a JSON file containing various data items (as an example) that I am utilizing with handlebars.js to generate templates. The challenge lies in displaying 15 stories (each within their own div) on page load while shuffling their positions upon each r ...

Can you have two onclick events triggered by a single Div? (ASP.NET / HTML)

I am currently working with Div's and facing a challenge of handling 2 events with just one Div-Click.. I wanted to use both onclick="" and OnClientClick, but it seems that when using a Div, I cannot make use of OnClientClick. Can anyone provide me ...

Guide on implementing recursion in JavaScript by accepting parameters as inputs

Could you please help me identify the error in this code snippet? I'm having trouble implementing recursion without parameters. The code only seems to work when I remove the parameters. Code Snippet let number = document.getElementById("inputN").val ...

Utilizing encoding and decoding techniques in PHP and JavaScript with robust data attribute validation

I am utilizing data attributes to transfer information from HTML to JavaScript. The data attributes are derived from MySQL data, so they may contain spaces, resulting in validation errors since spaces are not permitted within attributes. My proposed solut ...

Exporting a Component with React can be done in two ways: named exports and

There's a common syntax I've come across in various files: import React, {Component} from react; While I grasp the concept of named exports and default exports individually, I'm uncertain about how React manages this when exporting its cod ...

Effective Strategies for Preserving Form Input Values during Validation Failure in Spring MVC

I am currently working on validating user input, and I want the user's input fields to be retained in case of any validation errors. This is how I have set up my input fields: <form:input path="firstName" class="text short" id="firstName" value=" ...

React - Why does the screen sometimes flash white after server rendering?

While working on server rendering in React JS during development, I successfully achieved the same checksum between the server render and client render. Despite the client render being identical to the server render, there is a noticeable white flash on ...

Discovering ways to enhance time multiplication with JavaScript

My MVC model provides me with a timespan like this: timeTaken = "00:01:00"; Along with a multiplier value of multiply = "3"; The end result should be 00:03:00 What would be the most efficient way to calculate this time? I'm not well-versed in ...

Which tag should I use, <b> or <mark>, to emphasize important marketing terms within a paragraph?

Trying to emphasize specific keywords in a paragraph of text can be challenging. I'm currently puzzled about the distinction between the <b> and <mark> tags. These words are highlighted because they play a crucial role in marketing, prompt ...

change content of attached document when clicked

On all of my pages, I have included my header.php file. However, I am facing an issue with destroying sessions. Even though I have a logout.php page where I attempt to destroy the session, it is not happening as expected. The session remains registered wit ...

Exploring the world of symbols and characters: Font Awesome, Unicode, and Variable integration within React-Native

I am looking to incorporate fontAwesome icons into my app. Currently, I can display icons using string type values like this: <Text style={{fontFamily: 'fontAwesome'}}>&#xf0e8;</Text> This method works perfectly. However, I wan ...

How can I retrieve my array state in a different router page using VUEJS and VUEX?

I have created a page with two routes - one for the home page and another for the configuration where users can decide what content should be displayed on that container. In the configuration panel, I was able to retrieve input values and stored them in my ...

Creating a custom design for your chatbox using Tailwind CSS is a great way to

I'm looking to style a chat box using the map function to populate data. Currently, the items are displayed in a simple downward and inline fashion. However, I would like to achieve a staggered effect similar to messaging apps or text conversations. ...

Utilizing Jquery to Load JSON Arrays as Tooltip Messages

I have successfully loaded the descriptions of my JSON variable into my script as tooltips. However, I am encountering two issues: When hovering over one sentence in my table, tooltips for all four sentences appear. It seems like I am unable to revert my ...

Developing a dynamic web application using Asp.Net Core integrated with React and material

After setting up an Asp.Net Core project using the react template, I decided to incorporate material-ui by following the steps outlined on this page. However, encountered some dependency issues along the way. To resolve them, I had to update the react and ...

Steps for importing an external .js file into a Vue 2 component

Hello, I am currently working on vue.js 2 and I have come across a problem with the JavaScript part. I would like to include the general.js file in my posts.vue file. Can anyone provide assistance with this? Your help would be greatly appreciated :) Below ...

Integrating Labels on External Websites with ASP.NET

I have been developing a website that needs to display a counter on the home page. To accomplish this, I used an asp label that counts and displays the database records (e.g. 180000) with no issues at all. However, now I am facing a new challenge. I want ...