Skip to content

Commit 8b63603

Browse files
matskoNarretz
authored andcommitted
fix($animate): allow enabled children to animate on disabled parents
Prior to this fix if a parent container disabled animations for itself then no children could be enabled explicity via `$animate.enabled`. This patch allows for that to work. Closes angular#13179 Closes angular#13695
1 parent d91cf16 commit 8b63603

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

src/ngAnimate/animateQueue.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
263263
bool = !recordExists;
264264
} else {
265265
// (element, bool) - Element setter
266-
bool = !!bool;
267-
if (!bool) {
268-
disabledElementsLookup.put(node, true);
269-
} else if (recordExists) {
270-
disabledElementsLookup.remove(node);
271-
}
266+
disabledElementsLookup.put(node, !bool);
272267
}
273268
}
274269
}
@@ -580,6 +575,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
580575
var rootElementDetected = isMatchingElement(element, $rootElement);
581576
var parentAnimationDetected = false;
582577
var animateChildren;
578+
var elementDisabled = disabledElementsLookup.get(getDomNode(element));
583579

584580
var parentHost = element.data(NG_ANIMATE_PIN_DATA);
585581
if (parentHost) {
@@ -604,7 +600,16 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
604600
// therefore we can't allow any animations to take place
605601
// but if a parent animation is class-based then that's ok
606602
if (!parentAnimationDetected) {
607-
parentAnimationDetected = details.structural || disabledElementsLookup.get(parentNode);
603+
var parentElementDisabled = disabledElementsLookup.get(parentNode);
604+
605+
// disable animations if the user hasn't explicitly enabled animations on the
606+
// current element
607+
if (parentElementDisabled === true && elementDisabled !== false) {
608+
elementDisabled = true;
609+
} else if (parentElementDisabled === false) {
610+
elementDisabled = false;
611+
}
612+
parentAnimationDetected = details.structural;
608613
}
609614

610615
if (isUndefined(animateChildren) || animateChildren === true) {
@@ -639,7 +644,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
639644
parentElement = parentElement.parent();
640645
}
641646

642-
var allowAnimation = !parentAnimationDetected || animateChildren;
647+
var allowAnimation = (!parentAnimationDetected || animateChildren) && elementDisabled !== true;
643648
return allowAnimation && rootElementDetected && bodyElementDetected;
644649
}
645650

test/ngAnimate/animateSpec.js

+29
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,35 @@ describe("animations", function() {
304304
$rootScope.$digest();
305305
expect(capturedAnimation).toBeTruthy();
306306
}));
307+
308+
it('should run animations on an element and its children if explicitly enabled, even if animations are disabled on the parent',
309+
inject(function($animate, $rootScope) {
310+
311+
var child = jqLite('<div></div>');
312+
element.append(child);
313+
parent.append(element);
314+
315+
$animate.enabled(parent, false);
316+
317+
$animate.addClass(element, 'red');
318+
$rootScope.$digest();
319+
expect(capturedAnimation).toBeFalsy();
320+
321+
$animate.addClass(child, 'red');
322+
$rootScope.$digest();
323+
expect(capturedAnimation).toBeFalsy();
324+
325+
$animate.enabled(element, true);
326+
327+
$animate.addClass(element, 'blue');
328+
$rootScope.$digest();
329+
expect(capturedAnimation).toBeTruthy();
330+
capturedAnimation = null;
331+
332+
$animate.addClass(child, 'blue');
333+
$rootScope.$digest();
334+
expect(capturedAnimation).toBeTruthy();
335+
}));
307336
});
308337

309338
it('should strip all comment nodes from the animation and not issue an animation if not real elements are found',

0 commit comments

Comments
 (0)