From e53ff431e1472c0b2d5405d267d4e403ca31087e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Sat, 2 Nov 2013 14:14:13 -0400 Subject: [PATCH] fix($animate): ensure the active class is not applied if cancelled during reflow Closes #4699 --- src/ngAnimate/animate.js | 5 +++++ test/ngAnimate/animateSpec.js | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/ngAnimate/animate.js b/src/ngAnimate/animate.js index 64be7ba7f65a..ad192a5b3e77 100644 --- a/src/ngAnimate/animate.js +++ b/src/ngAnimate/animate.js @@ -898,6 +898,11 @@ angular.module('ngAnimate', ['ng']) // This triggers a reflow which allows for the transition animation to kick in. afterReflow(function() { + if(!element.hasClass(className)) { + done(); + return; + } + if(timings.transitionDuration > 0) { node.style[transitionProp + propertyKey] = ''; if(ii > 0 && stagger.transitionDelay > 0 && stagger.transitionDuration === 0) { diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js index 207cfedb21f1..ec37d8c3edbc 100644 --- a/test/ngAnimate/animateSpec.js +++ b/test/ngAnimate/animateSpec.js @@ -1723,6 +1723,29 @@ describe("ngAnimate", function() { }); }); + it("should not perform the active class animation if the animation has been cancelled before the reflow occurs", function() { + inject(function($compile, $rootScope, $animate, $sniffer, $timeout) { + if(!$sniffer.transitions) return; + + ss.addRule('.animated.ng-enter', '-webkit-transition: 2s linear all;' + + 'transition: 2s linear all;'); + + var element = html($compile('
...
')($rootScope)); + var child = $compile('
...
')($rootScope); + + $animate.enter(child, element); + $rootScope.$digest(); + + expect(child.hasClass('ng-enter')).toBe(true); + + $animate.leave(child); + $rootScope.$digest(); + + $timeout.flush(); + expect(child.hasClass('ng-enter-active')).toBe(false); + }); + }); + // it("should add and remove CSS classes and perform CSS animations during the process", // inject(function($compile, $rootScope, $animate, $sniffer, $timeout) { //