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

Commit 3a3db69

Browse files
committed
fix(ngAnimate): class-based animations must not set addClass/removeClass CSS classes on the element
With the abstraction system that ngAnimate uses, $animateCss internally sets the provided `event` as a CSS class on the element. In this situation the `addClass` and `removeClass` events on the element as a CSS class. This should not happen with class-based animations and this feature is unnecessary and has now been removed. Closes #11810
1 parent 2327f5a commit 3a3db69

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

src/ngAnimate/animateCssDriver.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,20 @@ var $$AnimateCssDriverProvider = ['$$animationProvider', function($$animationPro
226226
var element = animationDetails.element;
227227
var options = animationDetails.options || {};
228228

229-
options.structural = animationDetails.structural;
230-
231-
// structural animations ensure that the CSS classes are always applied
232-
// before the detection starts.
233-
options.applyClassesEarly = options.structural;
234-
235-
// we special case the leave animation since we want to ensure that
236-
// the element is removed as soon as the animation is over. Otherwise
237-
// a flicker might appear or the element may not be removed until all
238-
// the other animations have completed themselves (which would then
239-
// leave a pending element in the background).
240-
options.event = animationDetails.event;
241-
if (options.event === 'leave') {
242-
options.onDone = options.domOperation;
229+
if (animationDetails.structural) {
230+
// structural animations ensure that the CSS classes are always applied
231+
// before the detection starts.
232+
options.structural = options.applyClassesEarly = true;
233+
234+
// we special case the leave animation since we want to ensure that
235+
// the element is removed as soon as the animation is over. Otherwise
236+
// a flicker might appear or the element may not be removed at all
237+
options.event = animationDetails.event;
238+
if (options.event === 'leave') {
239+
options.onDone = options.domOperation;
240+
}
241+
} else {
242+
options.event = null;
243243
}
244244

245245
var animator = $animateCss(element, options);

test/ngAnimate/animateCssDriverSpec.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,21 @@ describe("ngAnimate $$animateCssDriver", function() {
9797
expect(isFunction(runner.start)).toBeTruthy();
9898
}));
9999

100-
it("should signal $animateCss to apply the classes early when an event is present", inject(function() {
100+
it("should signal $animateCss to apply the classes early when animation is structural", inject(function() {
101101
driver({ element: element, structural: true });
102102
expect(capturedAnimation[1].applyClassesEarly).toBeTruthy();
103103

104104
driver({ element: element });
105105
expect(capturedAnimation[1].applyClassesEarly).toBeFalsy();
106106
}));
107+
108+
it("should only set the event value if the animation is structural", inject(function() {
109+
driver({ element: element, structural: true, event: 'superman' });
110+
expect(capturedAnimation[1].event).toBe('superman');
111+
112+
driver({ element: element, event: 'batman' });
113+
expect(capturedAnimation[1].event).toBeFalsy();
114+
}));
107115
});
108116

109117
describe("anchored animations", function() {
@@ -214,7 +222,9 @@ describe("ngAnimate $$animateCssDriver", function() {
214222
'out': jqLite('<div></div>')
215223
};
216224

225+
fromAnimation.structural = true;
217226
fromAnimation.element.append(anchorAnimation['out']);
227+
toAnimation.structural = true;
218228
toAnimation.element.append(anchorAnimation['in']);
219229

220230
var animator = driver({
@@ -241,6 +251,9 @@ describe("ngAnimate $$animateCssDriver", function() {
241251
element.addClass(details.event);
242252
};
243253

254+
fromAnimation.structural = true;
255+
toAnimation.structural = true;
256+
244257
var runner = driver({
245258
from: fromAnimation,
246259
to: toAnimation
@@ -267,6 +280,9 @@ describe("ngAnimate $$animateCssDriver", function() {
267280
});
268281
});
269282
inject(function() {
283+
fromAnimation.structural = true;
284+
toAnimation.structural = true;
285+
270286
var runner = driver({
271287
from: fromAnimation,
272288
to: toAnimation
@@ -907,8 +923,11 @@ describe("ngAnimate $$animateCssDriver", function() {
907923
it("should pass the provided domOperation into $animateCss to be run right after the element is animated if a leave animation is present",
908924
inject(function($rootElement, $$rAF) {
909925

926+
toAnimation.structural = true;
910927
toAnimation.event = 'enter';
911928
toAnimation.options = {};
929+
930+
fromAnimation.structural = true;
912931
fromAnimation.event = 'leave';
913932
fromAnimation.options = {};
914933

0 commit comments

Comments
 (0)