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

Commit e001400

Browse files
committed
fix(ngAnimate): ensure that shared CSS classes between anchor nodes are retained
This patch ensures that all of the CSS classes that exist on both anchor nodes (the nodes that contain a `ng-animate-ref` attribute) are not removed from the cloned element during the anchor animation. (Previously the `in` animation would accidentally remove the CSS classes of the first element.) Closes #11681
1 parent 1002b80 commit e001400

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/ngAnimate/animateCssDriver.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var $$AnimateCssDriverProvider = ['$$animationProvider', function($$animationPro
4545

4646
function prepareAnchoredAnimation(classes, outAnchor, inAnchor) {
4747
var clone = jqLite(getDomNode(outAnchor).cloneNode(true));
48-
var startingClasses = filterCssClasses(clone.attr('class') || '');
48+
var startingClasses = filterCssClasses(getClassVal(clone));
4949
var anchorClasses = pendClasses(classes, NG_ANIMATE_ANCHOR_SUFFIX);
5050

5151
outAnchor.addClass(NG_ANIMATE_SHIM_CLASS_NAME);
@@ -140,13 +140,19 @@ var $$AnimateCssDriverProvider = ['$$animationProvider', function($$animationPro
140140
});
141141
}
142142

143+
function getClassVal(element) {
144+
return element.attr('class') || '';
145+
}
146+
143147
function prepareInAnimation() {
144-
var endingClasses = filterCssClasses(inAnchor.attr('class'));
145-
var classes = getUniqueValues(endingClasses, startingClasses);
148+
var endingClasses = filterCssClasses(getClassVal(inAnchor));
149+
var toAdd = getUniqueValues(endingClasses, startingClasses);
150+
var toRemove = getUniqueValues(startingClasses, endingClasses);
151+
146152
return $animateCss(clone, {
147153
to: calculateAnchorStyles(inAnchor),
148-
addClass: NG_IN_ANCHOR_CLASS_NAME + ' ' + classes,
149-
removeClass: NG_OUT_ANCHOR_CLASS_NAME + ' ' + startingClasses,
154+
addClass: NG_IN_ANCHOR_CLASS_NAME + ' ' + toAdd,
155+
removeClass: NG_OUT_ANCHOR_CLASS_NAME + ' ' + toRemove,
150156
delay: true
151157
});
152158
}

test/ngAnimate/animateCssDriverSpec.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -802,9 +802,9 @@ describe("ngAnimate $$animateCssDriver", function() {
802802
captureLog.pop().runner.end();
803803
$$rAF.flush();
804804

805-
var outAnimation = captureLog.pop();
806-
var clonedAnchor = outAnimation.element;
807-
var details = outAnimation.args[1];
805+
var inAnimation = captureLog.pop();
806+
var clonedAnchor = inAnimation.element;
807+
var details = inAnimation.args[1];
808808

809809
var addedClasses = details.addClass.split(' ');
810810
var removedClasses = details.removeClass.split(' ');
@@ -818,6 +818,11 @@ describe("ngAnimate $$animateCssDriver", function() {
818818
expect(removedClasses).not.toContain('brown');
819819
expect(removedClasses).not.toContain('black');
820820

821+
expect(removedClasses).not.toContain('red');
822+
expect(removedClasses).not.toContain('blue');
823+
824+
inAnimation.runner.end();
825+
821826
expect(clonedAnchor).toHaveClass('red');
822827
expect(clonedAnchor).toHaveClass('blue');
823828
}));

0 commit comments

Comments
 (0)