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

Commit 592bf51

Browse files
committed
fix($animateCss): consider options.delay value for closing timeout
Previously, options.delay was only considered when a class added an extra transition style (which leads to style recalculation). Fixes #13355 Closes #13363
1 parent 8cdafe4 commit 592bf51

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

src/ngAnimate/animateCss.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,12 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
622622
}
623623

624624
if (options.delay != null) {
625-
var delayStyle = parseFloat(options.delay);
625+
var delayStyle;
626+
if (typeof options.delay !== "boolean") {
627+
delayStyle = parseFloat(options.delay);
628+
// number in options.delay means we have to recalculate the delay for the closing timeout
629+
maxDelay = Math.max(delayStyle, 0);
630+
}
626631

627632
if (flags.applyTransitionDelay) {
628633
temporaryStyles.push(getCssDelayStyle(delayStyle));

test/ngAnimate/animateCssSpec.js

+68
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,74 @@ describe("ngAnimate $animateCss", function() {
12341234
$timeout.flush();
12351235
}).not.toThrow();
12361236
}));
1237+
1238+
it("should consider a positive options.delay value for the closing timeout",
1239+
inject(function($animateCss, $rootElement, $timeout, $document) {
1240+
1241+
var element = jqLite('<div></div>');
1242+
$rootElement.append(element);
1243+
jqLite($document[0].body).append($rootElement);
1244+
1245+
var options = {
1246+
delay: 3,
1247+
duration: 3,
1248+
to: {
1249+
height: '100px'
1250+
}
1251+
};
1252+
1253+
var animator = $animateCss(element, options);
1254+
1255+
animator.start();
1256+
triggerAnimationStartFrame();
1257+
1258+
// At this point, the animation should still be running (closing timeout is 7500ms ... duration * 1.5 + delay => 7.5)
1259+
$timeout.flush(7000);
1260+
1261+
expect(element.css(prefix + 'transition-delay')).toBe('3s');
1262+
expect(element.css(prefix + 'transition-duration')).toBe('3s');
1263+
1264+
// Let's flush the remaining amout of time for the timeout timer to kick in
1265+
$timeout.flush(500);
1266+
1267+
dump(element.attr('style'));
1268+
expect(element.css(prefix + 'transition-duration')).toBeOneOf('', '0s');
1269+
expect(element.css(prefix + 'transition-delay')).toBeOneOf('', '0s');
1270+
}));
1271+
1272+
it("should ignore a boolean options.delay value for the closing timeout",
1273+
inject(function($animateCss, $rootElement, $timeout, $document) {
1274+
1275+
var element = jqLite('<div></div>');
1276+
$rootElement.append(element);
1277+
jqLite($document[0].body).append($rootElement);
1278+
1279+
var options = {
1280+
delay: true,
1281+
duration: 3,
1282+
to: {
1283+
height: '100px'
1284+
}
1285+
};
1286+
1287+
var animator = $animateCss(element, options);
1288+
1289+
animator.start();
1290+
triggerAnimationStartFrame();
1291+
1292+
// At this point, the animation should still be running (closing timeout is 4500ms ... duration * 1.5 => 4.5)
1293+
$timeout.flush(4000);
1294+
1295+
expect(element.css(prefix + 'transition-delay')).toBeOneOf('initial', '0s');
1296+
expect(element.css(prefix + 'transition-duration')).toBe('3s');
1297+
1298+
// Let's flush the remaining amout of time for the timeout timer to kick in
1299+
$timeout.flush(500);
1300+
1301+
expect(element.css(prefix + 'transition-duration')).toBeOneOf('', '0s');
1302+
expect(element.css(prefix + 'transition-delay')).toBeOneOf('', '0s');
1303+
}));
1304+
12371305
});
12381306

12391307
describe("getComputedStyle", function() {

0 commit comments

Comments
 (0)