Skip to content

Commit b99f4d5

Browse files
committed
fix(ngAnimate): ensure CSS transitions/keyframes can be defined on the active classes
This allows for CSS transitions to be defined on the active CSS class if desired. Closes angular#12631
1 parent 01326be commit b99f4d5

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/ngAnimate/animateCss.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,8 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
577577
flags.applyAnimationDuration = options.duration && flags.hasAnimations;
578578
flags.applyTransitionDelay = truthyTimingValue(options.delay) && (flags.applyTransitionDuration || flags.hasTransitions);
579579
flags.applyAnimationDelay = truthyTimingValue(options.delay) && flags.hasAnimations;
580-
flags.recalculateTimingStyles = addRemoveClassName.length > 0;
580+
flags.recalculateTimingStyles = addRemoveClassName.length > 0 ||
581+
(activeClasses.length > 0 && !isStructural);
581582

582583
if (flags.applyTransitionDuration || flags.applyAnimationDuration) {
583584
maxDuration = options.duration ? parseFloat(options.duration) : maxDuration;

test/ngAnimate/integrationSpec.js

+30
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,36 @@ describe('ngAnimate integration tests', function() {
338338
expect($animate.reflows).toBe(10);
339339
});
340340
});
341+
342+
they('should always run an animation if $prop styles are defined amoung the active CSS classes',
343+
['transition', 'keyframe'], function(event) {
344+
345+
module('ngAnimateMock');
346+
inject(function($animate, $compile, $rootScope, $rootElement, $document, $$rAF) {
347+
element = jqLite('<div ng-class="klass">animate me</div>');
348+
element.addClass('animate-' + event);
349+
350+
ss.addRule('.animate-transition.red-add-active', 'transition:0.5s linear all; background:red;');
351+
ss.addRule('.animate-keyframe.red-add-active', 'animation:0.5s linear animateRed;');
352+
353+
$rootElement.append(element);
354+
jqLite($document[0].body).append($rootElement);
355+
356+
$compile(element)($rootScope);
357+
$rootScope.$digest();
358+
359+
expect($animate.reflows).toBe(0);
360+
361+
$rootScope.klass = 'red';
362+
$compile(element)($rootScope);
363+
$rootScope.$digest();
364+
$$rAF.flush();
365+
366+
expect(element).toHaveClass('red');
367+
expect(element).toHaveClass('red-add');
368+
expect(element).toHaveClass('red-add-active');
369+
});
370+
});
341371
});
342372

343373
describe('JS animations', function() {

0 commit comments

Comments
 (0)