Skip to content

Commit 51b3727

Browse files
crisbetojosephperrott
authored andcommitted
fix(drag-drop): account for transition-delay when waiting for the animation to finish (#12466)
Currently we have some functionality that waits for the preview's animation to finish and falls back to a timeout, based on the computed `transition-duration`, however that fallback doesn't account for the case where the element has a `transition-delay`. These changes account for the delay.
1 parent 2446318 commit 51b3727

File tree

1 file changed

+16
-8
lines changed
  • src/cdk-experimental/drag-drop

1 file changed

+16
-8
lines changed

src/cdk-experimental/drag-drop/drag.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ export class CdkDrag<T = any> implements OnDestroy {
462462
// we need to trigger a style recalculation in order for the `cdk-drag-animating` class to
463463
// apply its style, we take advantage of the available info to figure out whether we need to
464464
// bind the event in the first place.
465-
const duration = this._getTransitionDurationInMs(this._preview);
465+
const duration = getTransitionDurationInMs(this._preview);
466466

467467
if (duration === 0) {
468468
return Promise.resolve();
@@ -547,17 +547,25 @@ export class CdkDrag<T = any> implements OnDestroy {
547547

548548
this._placeholder = this._placeholderRef = null!;
549549
}
550+
}
550551

551-
/** Gets the `transition-duration` of an element in milliseconds. */
552-
private _getTransitionDurationInMs(element: HTMLElement): number {
553-
const rawDuration = getComputedStyle(element).getPropertyValue('transition-duration');
552+
/** Parses a CSS time value to milliseconds. */
553+
function parseCssTimeUnitsToMs(value: string): number {
554+
// Some browsers will return it in seconds, whereas others will return milliseconds.
555+
const multiplier = value.toLowerCase().indexOf('ms') > -1 ? 1 : 1000;
556+
return parseFloat(value) * multiplier;
557+
}
554558

555-
// Some browsers will return it in seconds, whereas others will return milliseconds.
556-
const multiplier = rawDuration.toLowerCase().indexOf('ms') > -1 ? 1 : 1000;
557-
return parseFloat(rawDuration) * multiplier;
558-
}
559+
/** Gets the transition duration, including the delay, of an element in milliseconds. */
560+
function getTransitionDurationInMs(element: HTMLElement): number {
561+
const computedStyle = getComputedStyle(element);
562+
const rawDuration = computedStyle.getPropertyValue('transition-duration');
563+
const rawDelay = computedStyle.getPropertyValue('transition-delay');
564+
565+
return parseCssTimeUnitsToMs(rawDuration) + parseCssTimeUnitsToMs(rawDelay);
559566
}
560567

568+
561569
/** Point on the page or within an element. */
562570
interface Point {
563571
x: number;

0 commit comments

Comments
 (0)