Issue with opacity transitions in Chrome on React application

I am currently developing a pomodoro clock using React. My goal is to have the message text (e.g. "Set a time", "Focus," etc.) and the play/reset button fade out and in when the play/reset button is pressed. So, when the play button is clicked, "Set a time" would fade out while "Focus" fades in along with the reset button once the timer starts.

Everything works smoothly in Firefox, but I am encountering issues with the fade-in effect in Chrome, even after trying to add the -webkit- prefix vendor. Additionally, in Internet Explorer, the message element resets to 0 opacity after the fade-in animation.

You can view my code and a live demo at this codesandbox link.

I am utilizing the react-transition-group library to implement transitions on elements that need to fade in and out during mounting and dismounting.

The relevant JSX code can be found at the bottom of PomodoroTimer.jsx or accessible here for convenience:

  <CSSTransitionGroup
    transitionName="fade"
    transitionEnterTimeout={500}
    transitionLeaveTimeout={500}
  >
    {!this.state.timerActive ? 
    <h3 className="message" key="set">Set a time.</h3> :
    (this.state.time < 50) ? 
    <h3 className="message" key="done">Done.</h3> : 
    this.state.timerType == "Rest" ?
    <h3 className="message" key="rest">Rest.</h3> :
    <h3 className="message" key="focus">Focus.</h3>}
  </CSSTransitionGroup>

The pertinent CSS code is located in PomodoroTimer.css or below:

.fade-enter {
  opacity: 0;
}

.fade-enter.fade-enter-active {
  opacity: 1;
  transition: opacity 500ms ease-out;
  transition-delay: 500ms;
}

.fade-leave {
  opacity: 1;
}

.fade-leave.fade-leave-active {
  opacity: 0;
  transition: opacity 500ms ease-in;
}

Your assistance will be greatly appreciated!

Answer №1

The issue here lies in the discrepancy between the animation times set in the CSS and the transition times defined in the code snippet below:

.fade-enter {
  opacity: 0;
}

.fade-enter.fade-enter-active {
  opacity: 1;
  transition: opacity 5000ms ease-out;
  transition-delay: 5000ms;
}

.fade-leave {
  opacity: 1;
}

.fade-leave.fade-leave-active {
  opacity: 0;
  transition: opacity 5000ms ease-in;
}

The fade-enter and fade-leave classes are applied to elements based on the time specified in the following code:

<CSSTransitionGroup
   transitionName="fade"
   transitionEnterTimeout={5000}
   transitionLeaveTimeout={5000}
>

These classes are added or removed after the specific amount of time mentioned in the transitionEnterTimeout={500} and transitionLeaveTimeout={500}. This means that even if you change the CSS animation duration to 5000ms, the classes will still be affected by the timings specified in the code snippet.

Therefore, it is important to keep the timing consistent in both places for the desired effect.

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

What steps can I take to prevent constantly re-fetching a disabled CSS file?

I'm currently in the process of implementing a dark theme on my website, and my current method involves using 2 style sheets: <link rel="stylesheet" type="text/css" href="/flatly.css"> <link rel="stylesheet& ...

Enhancing the appearance of an Angular.js application

On the same page, there are two buttons - one for buying and one for selling. It appears that both buttons share the same HTML instance. This creates a problem when trying to style them individually using classes, ids, or other HTML-targeted selectors, as ...

Tips on aligning a v-btn alongside v-expansion-panels on the same row

Struggling with aligning my layout. Trying to get a single set of v-expansion-panels and a v-btn in the same row, both visually centered within a card. I managed to almost achieve it in this codepen: https://codepen.io/anzuj/pen/PoPPbdw with the following ...

Troubleshooting a React app deployment on Heroku: Dealing with the JS heap overflow

Seeking Solution: I have been facing a challenge while trying to deploy my React application on Heroku. Despite successful build and deployment, the app crashes immediately upon startup. Upon investigation, I suspect that the issue may be related to the s ...

Adding a gap between the Bootstrap navbar and jumbotron for better spacing

Upon examining the Bootstrap example provided at: http://getbootstrap.com/examples/navbar/ I noticed there is a gap between the jumbotron and the navbar. After delving into the example's CSS, I found that disabling this rule (twice): .navbar { ...

Transforming the DOM using jQuery

I am looking to manipulate the DOM using jQuery. This is the initial source code: <td class="name"><a href="position_details.php?x=-109&amp;y=95">21</a> </td> <td class="name"><a href="position_details.php?x=-109& ...

Ways to specify the default value for a component

A sample of my custom component code (Amount.tsx) is shown below: const Price = ({ price, prevPrice }) => { return ( <div className="product-amount"> <div className="price"> {prevPrice ? (<del class ...

Is using display:table an effective approach for achieving equal height columns?

I am currently working on a responsive design project and I need two columns of equal height. I do not want to rely on JavaScript for this, and I prefer having some whitespace between the columns to enhance readability. I have tried two different layouts; ...

Tips for utilizing withNavigation from react-navigation in a TypeScript environment

Currently, I am working on building an app using react-native, react-navigation, and typescript. The app consists of only two screens - HomeScreen and ConfigScreen, along with one component named GoToConfigButton. Here is the code for both screens: HomeSc ...

Can we modify the cell width in knitr and pandoc?

When generating an HTML file using knitr/pandoc to display multiple tables in a loop, how can you ensure that each table has the same total width despite having varying numbers of cells? --- output: html_document: theme: cosmo --- {r results ="asis", e ...

Is it possible to make the clear indicator in react-select remain visible even after clearing the selection

How can I make the ClearIndicator remain visible after clearing in react-select? I have customized the selector ClearIndicator to display as a downward arrow by default, and when hovered over, it changes to a cross. However, after clicking the cross, I w ...

When modifying the state of an array within a component, certain values may be overwritten and lost in the process

Currently, I'm faced with the challenge of ensuring that a component displays a loading screen until all images have completed loading. This is necessary because there are approximately 25 images that must finish loading before the page can be display ...

Featuring a visual arrangement of categorized images with AngularJS for an interactive display

As I work on developing a web application with Angular, my goal is to create a grid layout that organizes items by category. Each row will represent a different category. Below is an example of the code structure I have in place: <ion-item ng-repeat="i ...

Restricting certain time ranges for specific dates in the DateRangePicker component of AntD React

Currently, I am in the process of developing a car booking application where I encounter an issue with disabling specific days and times in the DateRangePicker based on the selected car's bookings. My choice for the date picker component is the AntD ...

Discovering a method to detect clicks outside of a React functional component

Looking to identify when a click occurs outside of a React functional component. After stumbling upon an article, I followed the provided code but unfortunately, it didn't work as expected. Despite identifying the issue, I am still searching for a so ...

The `this` value is null within an onClick function of a ReactJS component

The issue occurs with the onClick method of <span className="nav-toggle">. The specific error message is: cannot read property setState of null. It seems to be related to the scoping of this or due to the asynchronous nature of the setState method. ...

React material-ui tablecell's onclick functionIncorporating onClick functionality into a React

I am trying to implement popovers that appear when a table cell in a Material UI table is clicked. I attempted to add an onclick function to the cell, but I am struggling to pass the element value to the function. How can I solve this issue? Below is a cod ...

Floating Label in Material Design Interface

Has anyone discovered a resolution for the issue of Material UI and React textfield not automatically floating the label? Here is the component where I am encountering this problem - the key is passed via Redux from another component and the main data is ...

Enter the UL element and modify the LI class if it contains the .has_children class

Seeking assistance in navigating through a UL element to modify the LI and nested UL classes when .has_children is detected. Take a look at this example: <ul class="nav navbar-nav"> <li class="first current parent">Link1</li> < ...

Instructions on obtaining a distinct daily array from the weather API array that provides a detailed 5-day weather report every 3 hours

Seeking assistance with my weather app development on React using axios with the openweathermap.org API. Currently stuck on getting data formatted in a specific way from the 5-day forecast it provides, totaling 40 reports over the 5 days. The API response ...