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

fix($animate): allow enabled children to animate on disabled parents #13695

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/ngAnimate/animateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
bool = !recordExists;
} else {
// (element, bool) - Element setter
bool = !!bool;
if (!bool) {
disabledElementsLookup.put(node, true);
} else if (recordExists) {
disabledElementsLookup.remove(node);
}
disabledElementsLookup.put(node, !bool);
}
}
}
Expand Down Expand Up @@ -574,6 +569,17 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
var parentAnimationDetected = false;
var animateChildren;

var PARENT_STATE_DISABLED = 1;
var PARENT_STATE_ENABLED = 2;
var parentElementDisabledState = 0;

var elementDisabledStatus = disabledElementsLookup.get(getDomNode(element));
if (elementDisabledStatus === true) {
parentElementDisabledState = PARENT_STATE_DISABLED;
} else if (elementDisabledStatus === false) {
parentElementDisabledState = PARENT_STATE_ENABLED;
}

var parentHost = element.data(NG_ANIMATE_PIN_DATA);
if (parentHost) {
parentElement = parentHost;
Expand All @@ -597,7 +603,15 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
// therefore we can't allow any animations to take place
// but if a parent animation is class-based then that's ok
if (!parentAnimationDetected) {
parentAnimationDetected = details.structural || disabledElementsLookup.get(parentNode);
var disabledStatus = disabledElementsLookup.get(parentNode);

// the user has `explicitly` allowed for animations to be enabled on this container
if (disabledStatus === true && parentElementDisabledState != PARENT_STATE_ENABLED) {
parentElementDisabledState = PARENT_STATE_DISABLED;
} else if (disabledStatus === false) {
parentElementDisabledState = PARENT_STATE_ENABLED;
}
parentAnimationDetected = details.structural;
}

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

var allowAnimation = !parentAnimationDetected || animateChildren;
var allowAnimation = (!parentAnimationDetected || animateChildren) && parentElementDisabledState != PARENT_STATE_DISABLED;
return allowAnimation && rootElementDetected && bodyElementDetected;
}

Expand Down
29 changes: 29 additions & 0 deletions test/ngAnimate/animateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,35 @@ describe("animations", function() {
$rootScope.$digest();
expect(capturedAnimation).toBeTruthy();
}));

it('should enable animations on the child element if explicitly allowed even if animations are disabled on the parent',
inject(function($animate, $rootScope) {

var child = jqLite('<div></div>');
element.append(child);
parent.append(element);

$animate.enabled(parent, false);

$animate.addClass(element, 'red');
$rootScope.$digest();
expect(capturedAnimation).toBeFalsy();

$animate.addClass(child, 'red');
$rootScope.$digest();
expect(capturedAnimation).toBeFalsy();

$animate.enabled(element, true);

$animate.addClass(element, 'blue');
$rootScope.$digest();
expect(capturedAnimation).toBeTruthy();
capturedAnimation = null;

$animate.addClass(child, 'blue');
$rootScope.$digest();
expect(capturedAnimation).toBeTruthy();
}));
});

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