Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b1a933e

Browse files
committedMay 7, 2015
fix(ngAnimate): class-based animations must set the addClass/removeClass class 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 1002b80 commit b1a933e

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed
 

‎src/ngAnimate/animateCssDriver.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,22 @@ var $$AnimateCssDriverProvider = ['$$animationProvider', function($$animationPro
215215
var element = animationDetails.element;
216216
var options = animationDetails.options || {};
217217

218-
options.structural = animationDetails.structural;
219-
220-
// structural animations ensure that the CSS classes are always applied
221-
// before the detection starts.
222-
options.applyClassesEarly = options.structural;
223-
224-
// we special case the leave animation since we want to ensure that
225-
// the element is removed as soon as the animation is over. Otherwise
226-
// a flicker might appear or the element may not be removed at all
227-
options.event = animationDetails.event;
228-
if (options.event === 'leave' && animationDetails.domOperation) {
229-
options.onDone = animationDetails.domOperation;
218+
if (animationDetails.structural) {
219+
// structural animations ensure that the CSS classes are always applied
220+
// before the detection starts.
221+
options.applyClassesEarly = true;
222+
options.structural = true;
223+
224+
// we special case the leave animation since we want to ensure that
225+
// the element is removed as soon as the animation is over. Otherwise
226+
// a flicker might appear or the element may not be removed at all
227+
options.event = animationDetails.event;
228+
229+
if (options.event === 'leave' && animationDetails.domOperation) {
230+
options.onDone = animationDetails.domOperation;
231+
}
232+
} else {
233+
options.event = null;
230234
}
231235

232236
return $animateCss(element, options);

‎test/ngAnimate/animateCssDriverSpec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ describe("ngAnimate $$animateCssDriver", function() {
103103
driver({ element: element });
104104
expect(capturedAnimation[1].applyClassesEarly).toBeFalsy();
105105
}));
106+
107+
it("should not provide a method into the $animateCss animation if the animation is not structural", inject(function() {
108+
driver({ element: element, structural: true, event: 'superman' });
109+
expect(capturedAnimation[1].event).toBe('superman');
110+
111+
driver({ element: element, event: 'batman' });
112+
expect(capturedAnimation[1].event).toBeFalsy();
113+
}));
106114
});
107115

108116
describe("anchored animations", function() {
@@ -209,7 +217,9 @@ describe("ngAnimate $$animateCssDriver", function() {
209217
'out': jqLite('<div></div>')
210218
};
211219

220+
fromAnimation.structural = true;
212221
fromAnimation.element.append(anchorAnimation['out']);
222+
toAnimation.structural = true;
213223
toAnimation.element.append(anchorAnimation['in']);
214224

215225
var animator = driver({
@@ -236,6 +246,9 @@ describe("ngAnimate $$animateCssDriver", function() {
236246
element.addClass(details.event);
237247
};
238248

249+
fromAnimation.structural = true;
250+
toAnimation.structural = true;
251+
239252
var runner = driver({
240253
from: fromAnimation,
241254
to: toAnimation
@@ -261,6 +274,9 @@ describe("ngAnimate $$animateCssDriver", function() {
261274
});
262275
});
263276
inject(function() {
277+
fromAnimation.structural = true;
278+
toAnimation.structural = true;
279+
264280
var runner = driver({
265281
from: fromAnimation,
266282
to: toAnimation
@@ -897,8 +913,10 @@ describe("ngAnimate $$animateCssDriver", function() {
897913
it("should pass the provided domOperation into $animateCss to be run right after the element is animated if a leave animation is present",
898914
inject(function($rootElement, $$rAF) {
899915

916+
toAnimation.structural = true;
900917
toAnimation.event = 'enter';
901918
fromAnimation.event = 'leave';
919+
fromAnimation.structural = true;
902920

903921
var leaveOp = function() { };
904922
fromAnimation.domOperation = leaveOp;

0 commit comments

Comments
 (0)
This repository has been archived.