Skip to content

Commit 531ea7c

Browse files
authored
fix(drag-drop): error on IE when document is being auto scrolled (#18757)
We have a code path where we call `contains` either on a DOM node or the `Document`, but on IE the `Document` doesn't support `contains` which results in an error. These changes add a workaround where we use the `documentElement` instead.
1 parent 0dbe23b commit 531ea7c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/cdk/drag-drop/drop-list-ref.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,14 +739,19 @@ export class DropListRef<T = any> {
739739
private _updateAfterScroll(scrolledParent: HTMLElement | Document,
740740
newTop: number,
741741
newLeft: number) {
742+
// Used when figuring out whether an element is inside the scroll parent. If the scrolled
743+
// parent is the `document`, we use the `documentElement`, because IE doesn't support `contains`
744+
// on the `document`.
745+
const scrolledParentNode =
746+
scrolledParent === this._document ? scrolledParent.documentElement : scrolledParent;
742747
const scrollPosition = this._parentPositions.get(scrolledParent)!.scrollPosition;
743748
const topDifference = scrollPosition.top - newTop;
744749
const leftDifference = scrollPosition.left - newLeft;
745750

746751
// Go through and update the cached positions of the scroll
747752
// parents that are inside the element that was scrolled.
748753
this._parentPositions.forEach((position, node) => {
749-
if (position.clientRect && scrolledParent !== node && scrolledParent.contains(node)) {
754+
if (position.clientRect && scrolledParent !== node && scrolledParentNode.contains(node)) {
750755
adjustClientRect(position.clientRect, topDifference, leftDifference);
751756
}
752757
});

0 commit comments

Comments
 (0)