Skip to content

Commit 178eb87

Browse files
airatomatsko
authored andcommitted
fix($animate): remove the ng-animate className after canceling animation
Closes angular#7784 Closes angular#7801 Closes angular#7872
1 parent 600a41a commit 178eb87

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/ngAnimate/animate.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -921,10 +921,9 @@ angular.module('ngAnimate', ['ng'])
921921
//cancel all animations when a structural animation takes place
922922
for(var klass in runningAnimations) {
923923
animationsToCancel.push(runningAnimations[klass]);
924-
cleanup(element, klass);
925924
}
926-
runningAnimations = {};
927-
totalActiveAnimations = 0;
925+
ngAnimateState = {};
926+
cleanup(element, true);
928927
}
929928
} else if(lastAnimation.event == 'setClass') {
930929
animationsToCancel.push(lastAnimation);
@@ -947,6 +946,9 @@ angular.module('ngAnimate', ['ng'])
947946
}
948947
}
949948

949+
runningAnimations = ngAnimateState.active || {};
950+
totalActiveAnimations = ngAnimateState.totalActive || 0;
951+
950952
if(runner.isClassBased && !runner.isSetClassOperation && !skipAnimation) {
951953
skipAnimation = (animationEvent == 'addClass') == element.hasClass(className); //opposite of XOR
952954
}

test/ngAnimate/animateSpec.js

+40
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,46 @@ describe("ngAnimate", function() {
690690
expect(child.hasClass('animation-cancelled')).toBe(true);
691691
}));
692692

693+
it("should remove the .ng-animate className after a former animation was cancelled and then after the follow-up class-based animation has completed", function() {
694+
var addClassDone, removeClassDone,
695+
addClassDoneSpy = jasmine.createSpy(),
696+
removeClassDoneSpy = jasmine.createSpy();
697+
698+
module(function($animateProvider) {
699+
$animateProvider.register('.hide', function() {
700+
return {
701+
addClass : function(element, className, done) {
702+
addClassDone = done;
703+
return addClassDoneSpy;
704+
},
705+
removeClass : function(element, className, done) {
706+
removeClassDone = done;
707+
return removeClassDoneSpy;
708+
}
709+
};
710+
});
711+
});
712+
713+
inject(function($animate, $rootScope, $sniffer, $timeout) {
714+
$animate.addClass(element, 'hide');
715+
716+
expect(element).toHaveClass('ng-animate');
717+
718+
$animate.triggerReflow();
719+
720+
$animate.removeClass(element, 'hide');
721+
expect(addClassDoneSpy).toHaveBeenCalled();
722+
723+
$animate.triggerReflow();
724+
725+
expect(element).toHaveClass('ng-animate');
726+
727+
removeClassDone();
728+
$animate.triggerCallbacks();
729+
730+
expect(element).not.toHaveClass('ng-animate');
731+
});
732+
});
693733

694734
it("should skip a class-based animation if the same element already has an ongoing structural animation",
695735
inject(function($animate, $rootScope, $sniffer, $timeout) {

0 commit comments

Comments
 (0)