Skip to content

Commit

Permalink
fix: Cross-browser animations
Browse files Browse the repository at this point in the history
  • Loading branch information
mhomolak committed Nov 29, 2016
1 parent 2ac1a17 commit 494018c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/js/component-owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,32 @@ class AlertsComponent extends React.Component {

handleClose = () => {

const whichTransitionEvent = () => {
let transition;
const transitions = {
transition: 'animationend',
WebkitTransition: 'webkitAnimationEnd'
};

Object.keys(transitions).forEach(function(transitionKey) {
if (targetAlert.style[transitionKey] !== undefined) {
transition = transitions[transitionKey];
}
});

return transition;
};

const reset = () => {
this.setState({ open: false, opacity: 0, closeProp: '' });
if (this.state.open === false) {
targetAlert.removeEventListener('webkitAnimationEnd', reset);
targetAlert.removeEventListener(whichTransitionEvent(), reset);
}
}

this.setState({ closeProp: 'close-title-animation' });

targetAlert.addEventListener('webkitAnimationEnd', reset);
targetAlert.addEventListener(whichTransitionEvent(), reset);

};

Expand All @@ -55,8 +71,6 @@ class AlertsComponent extends React.Component {
} <br/><br/><br/><br/>

<button className="test-button">Success</button>


</div>
);
}
Expand Down

0 comments on commit 494018c

Please sign in to comment.