Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
React: How can I apply CSS transition effects when an element is rendered?

I have a checkbox that, when checked, exposes part of a form, eg:

                        <label>
                            <input
                                name="postalAddressNeeded"
                                type="checkbox"
                                value={this.state.postalAddressNeeded}
                                onChange={this.handlePostalCheckChange}
                            />
                            My postal address is different my residential address
                        </label>

                        {postalAddressNeeded &&
                            <div>
                                <AddressAutocomplete />
                            </div>
                        }
                    </div>
                    }

This works, but I'd like to animate it to slide down when the checkbox is checked. To that affect I have created:

{postalAddressNeeded &&
  <div className={`js-inactive ${postalAddressNeeded ? 'js-slide-down-show' : 'js-slide-down-hide'}`}>
   <AddressAutocomplete />
  </div>
}

and in my CSS:

.js-inactive {
    height: 0px;
}

.js-slide-down-show {
    height: auto;
    -webkit-transition: height .3s ease;
}

.js-slide-down-hide {
    height: 0px;
    -webkit-transition: height .3s ease;
}

However this does not work - the element still appears but there are no animations.

I've investigated other ways of doing this IE with the react-transition-group plugin, but it looks like that does work with rendering elements.

Would anyone know of a way to achieve this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here is small sandbox, with some explanations in the styles.

In the comments, coot3 and Servesh Chaturvedi are both right, just combine their answers.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!