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

Commit 97d79ee

Browse files
committed
fix($animateCss): ensure animations execute if only a keyframeStyle is provided
`$animateCss` is a fan of transition animations, but it turns out that if only a keyframeStyle is provided into the animation upon constrution then it will quit because it assumes that nothing will be animated (since no classes or styles are being applied). This patch ensures that a keyframe style can solely be applied to an animation triggered with `$animateCss`. ```js // this will now work as expected $animateCss(element, { keyframeStyle: '1s rotate' }).start(); ``` Closes #12124 Closes #12340
1 parent e4aeae0 commit 97d79ee

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/ngAnimate/animateCss.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,14 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
560560
var fullClassName = classes + ' ' + setupClasses;
561561
var activeClasses = pendClasses(setupClasses, '-active');
562562
var hasToStyles = styles.to && Object.keys(styles.to).length > 0;
563-
564-
// there is no way we can trigger an animation since no styles and
565-
// no classes are being applied which would then trigger a transition
566-
if (!hasToStyles && !setupClasses) {
563+
var containsKeyframeAnimation = (options.keyframeStyle || '').length > 0;
564+
565+
// there is no way we can trigger an animation if no styles and
566+
// no classes are being applied which would then trigger a transition,
567+
// unless there a is raw keyframe value that is applied to the element.
568+
if (!containsKeyframeAnimation
569+
&& !hasToStyles
570+
&& !setupClasses) {
567571
return closeAndReturnNoopAnimator();
568572
}
569573

test/ngAnimate/animateCssSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,23 @@ describe("ngAnimate $animateCss", function() {
22042204
expect(element.css(prefix + 'animation-duration')).toEqual('5.5s');
22052205
expect(element.css(prefix + 'animation-name')).toEqual('my_animation');
22062206
}));
2207+
2208+
it("should be able to execute the animation if it is the only provided value",
2209+
inject(function($animateCss, $rootElement) {
2210+
2211+
var options = {
2212+
keyframeStyle: 'my_animation 5.5s 10s'
2213+
};
2214+
2215+
var animator = $animateCss(element, options);
2216+
2217+
animator.start();
2218+
triggerAnimationStartFrame();
2219+
2220+
expect(element.css(prefix + 'animation-delay')).toEqual('10s');
2221+
expect(element.css(prefix + 'animation-duration')).toEqual('5.5s');
2222+
expect(element.css(prefix + 'animation-name')).toEqual('my_animation');
2223+
}));
22072224
});
22082225

22092226
describe("[from] and [to]", function() {

0 commit comments

Comments
 (0)