Skip to content

Commit 14f3127

Browse files
committed
fix($animate): allow animations when pinned element is parent element
Previously, the animate queue would only detect pinned elements when they were the same element as the to-be-animated element. Related angular#12617 Closes angular#13466
1 parent a60e0f2 commit 14f3127

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

src/ngAnimate/animateQueue.js

+1
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
586586
parentHost = parentElement.data(NG_ANIMATE_PIN_DATA);
587587
if (parentHost) {
588588
parentElement = parentHost;
589+
rootElementDetected = true;
589590
}
590591
}
591592
}

test/ngAnimate/animateSpec.js

+34-16
Original file line numberDiff line numberDiff line change
@@ -1425,28 +1425,46 @@ describe("animations", function() {
14251425
}));
14261426

14271427

1428-
it('should allow an element to be pinned elsewhere and still be available in animations',
1429-
inject(function($animate, $compile, $document, $rootElement, $rootScope) {
1428+
they('should animate an element inside a pinned element that is the $prop element',
1429+
['same', 'parent', 'grandparent'],
1430+
function(elementRelation) {
1431+
inject(function($animate, $compile, $document, $rootElement, $rootScope) {
14301432

1431-
var innerParent = jqLite('<div></div>');
1432-
jqLite($document[0].body).append(innerParent);
1433-
innerParent.append($rootElement);
1433+
var pinElement, animateElement;
14341434

1435-
var element = jqLite('<div></div>');
1436-
jqLite($document[0].body).append(element);
1435+
var innerParent = jqLite('<div></div>');
1436+
jqLite($document[0].body).append(innerParent);
1437+
innerParent.append($rootElement);
14371438

1438-
$animate.addClass(element, 'red');
1439-
$rootScope.$digest();
1440-
expect(capturedAnimation).toBeFalsy();
1439+
switch (elementRelation) {
1440+
case 'same':
1441+
pinElement = jqLite('<div id="animate"></div>');
1442+
break;
1443+
case 'parent':
1444+
pinElement = jqLite('<div><div id="animate"></div></div>');
1445+
break;
1446+
case 'grandparent':
1447+
pinElement = jqLite('<div><div><div id="animate"></div></div></div>');
1448+
break;
1449+
}
14411450

1442-
$animate.pin(element, $rootElement);
1451+
jqLite($document[0].body).append(pinElement);
1452+
animateElement = jqLite($document[0].getElementById('animate'));
14431453

1444-
$animate.addClass(element, 'blue');
1445-
$rootScope.$digest();
1446-
expect(capturedAnimation).toBeTruthy();
1454+
$animate.addClass(animateElement, 'red');
1455+
$rootScope.$digest();
1456+
expect(capturedAnimation).toBeFalsy();
14471457

1448-
dealoc(element);
1449-
}));
1458+
// Pin the element to the app root to enable animations
1459+
$animate.pin(pinElement, $rootElement);
1460+
1461+
$animate.addClass(animateElement, 'blue');
1462+
$rootScope.$digest();
1463+
expect(capturedAnimation).toBeTruthy();
1464+
1465+
dealoc(pinElement);
1466+
});
1467+
});
14501468

14511469
it('should adhere to the disabled state of the hosted parent when an element is pinned',
14521470
inject(function($animate, $compile, $document, $rootElement, $rootScope) {

0 commit comments

Comments
 (0)