Skip to content

Commit 2323149

Browse files
airatomatsko
authored andcommitted
fix($animate): remove the ng-animate className after canceling animation
Closes angular#7784 Closes angular#7801 Closes angular#7894
1 parent 8252b8b commit 2323149

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
@@ -958,10 +958,9 @@ angular.module('ngAnimate', ['ng'])
958958
//cancel all animations when a structural animation takes place
959959
for(var klass in runningAnimations) {
960960
animationsToCancel.push(runningAnimations[klass]);
961-
cleanup(element, klass);
962961
}
963-
runningAnimations = {};
964-
totalActiveAnimations = 0;
962+
ngAnimateState = {};
963+
cleanup(element, true);
965964
}
966965
} else if(lastAnimation.event == 'setClass') {
967966
animationsToCancel.push(lastAnimation);
@@ -984,6 +983,9 @@ angular.module('ngAnimate', ['ng'])
984983
}
985984
}
986985

986+
runningAnimations = ngAnimateState.active || {};
987+
totalActiveAnimations = ngAnimateState.totalActive || 0;
988+
987989
if(runner.isClassBased && !runner.isSetClassOperation && !skipAnimation) {
988990
skipAnimation = (animationEvent == 'addClass') == element.hasClass(className); //opposite of XOR
989991
}

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 class after the next animation is run which interrupted the last animation", 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)