Skip to content

Commit 12ab1fa

Browse files
committed
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 495d40d commit 12ab1fa

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

src/ngAnimate/animateQueue.js

+22-8
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
256256
bool = !recordExists;
257257
} else {
258258
// (element, bool) - Element setter
259-
bool = !!bool;
260-
if (!bool) {
261-
disabledElementsLookup.put(node, true);
262-
} else if (recordExists) {
263-
disabledElementsLookup.remove(node);
264-
}
259+
disabledElementsLookup.put(node, !bool);
265260
}
266261
}
267262
}
@@ -574,6 +569,17 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
574569
var parentAnimationDetected = false;
575570
var animateChildren;
576571

572+
var PARENT_STATE_DISABLED = 1;
573+
var PARENT_STATE_ENABLED = 2;
574+
var parentElementDisabledState = 0;
575+
576+
var elementDisabledStatus = disabledElementsLookup.get(getDomNode(element));
577+
if (elementDisabledStatus === true) {
578+
parentElementDisabledState = PARENT_STATE_DISABLED;
579+
} else if (elementDisabledStatus === false) {
580+
parentElementDisabledState = PARENT_STATE_ENABLED;
581+
}
582+
577583
var parentHost = element.data(NG_ANIMATE_PIN_DATA);
578584
if (parentHost) {
579585
parentElement = parentHost;
@@ -597,7 +603,15 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
597603
// therefore we can't allow any animations to take place
598604
// but if a parent animation is class-based then that's ok
599605
if (!parentAnimationDetected) {
600-
parentAnimationDetected = details.structural || disabledElementsLookup.get(parentNode);
606+
var disabledStatus = disabledElementsLookup.get(parentNode);
607+
608+
// the user has `explicitly` allowed for animations to be enabled on this container
609+
if (disabledStatus === true && parentElementDisabledState != PARENT_STATE_ENABLED) {
610+
parentElementDisabledState = PARENT_STATE_DISABLED;
611+
} else if (disabledStatus === false) {
612+
parentElementDisabledState = PARENT_STATE_ENABLED;
613+
}
614+
parentAnimationDetected = details.structural;
601615
}
602616

603617
if (isUndefined(animateChildren) || animateChildren === true) {
@@ -632,7 +646,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
632646
parentElement = parentElement.parent();
633647
}
634648

635-
var allowAnimation = !parentAnimationDetected || animateChildren;
649+
var allowAnimation = (!parentAnimationDetected || animateChildren) && parentElementDisabledState != PARENT_STATE_DISABLED;
636650
return allowAnimation && rootElementDetected && bodyElementDetected;
637651
}
638652

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+
iit('should enable animations on the child element if explicitly allowed 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)