Skip to content

Commit

Permalink
fix($animate): ensure the active class is not applied if cancelled du…
Browse files Browse the repository at this point in the history
…ring reflow

Closes angular#4699
  • Loading branch information
matsko authored and jamesdaily committed Jan 27, 2014
1 parent 4c92b7d commit 2ceb180
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ngAnimate/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 23 additions & 0 deletions test/ngAnimate/animateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div>...</div>')($rootScope));
var child = $compile('<div class="animated">...</div>')($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) {
//
Expand Down

0 comments on commit 2ceb180

Please sign in to comment.