Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit e53ff43

Browse files
committed
fix($animate): ensure the active class is not applied if cancelled during reflow
Closes #4699
1 parent 974b6d4 commit e53ff43

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/ngAnimate/animate.js

+5
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,11 @@ angular.module('ngAnimate', ['ng'])
898898

899899
// This triggers a reflow which allows for the transition animation to kick in.
900900
afterReflow(function() {
901+
if(!element.hasClass(className)) {
902+
done();
903+
return;
904+
}
905+
901906
if(timings.transitionDuration > 0) {
902907
node.style[transitionProp + propertyKey] = '';
903908
if(ii > 0 && stagger.transitionDelay > 0 && stagger.transitionDuration === 0) {

test/ngAnimate/animateSpec.js

+23
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,29 @@ describe("ngAnimate", function() {
17231723
});
17241724
});
17251725

1726+
it("should not perform the active class animation if the animation has been cancelled before the reflow occurs", function() {
1727+
inject(function($compile, $rootScope, $animate, $sniffer, $timeout) {
1728+
if(!$sniffer.transitions) return;
1729+
1730+
ss.addRule('.animated.ng-enter', '-webkit-transition: 2s linear all;' +
1731+
'transition: 2s linear all;');
1732+
1733+
var element = html($compile('<div>...</div>')($rootScope));
1734+
var child = $compile('<div class="animated">...</div>')($rootScope);
1735+
1736+
$animate.enter(child, element);
1737+
$rootScope.$digest();
1738+
1739+
expect(child.hasClass('ng-enter')).toBe(true);
1740+
1741+
$animate.leave(child);
1742+
$rootScope.$digest();
1743+
1744+
$timeout.flush();
1745+
expect(child.hasClass('ng-enter-active')).toBe(false);
1746+
});
1747+
});
1748+
17261749
// it("should add and remove CSS classes and perform CSS animations during the process",
17271750
// inject(function($compile, $rootScope, $animate, $sniffer, $timeout) {
17281751
//

0 commit comments

Comments
 (0)