|
9 | 9 | import {ElementRef} from '@angular/core';
|
10 | 10 | import {DragDropRegistry} from './drag-drop-registry';
|
11 | 11 | import {Direction} from '@angular/cdk/bidi';
|
| 12 | +import {coerceElement} from '@angular/cdk/coercion'; |
12 | 13 | import {Subject} from 'rxjs';
|
13 | 14 | import {moveItemInArray} from './drag-utils';
|
14 | 15 | import {DragRefInternal as DragRef} from './drag-ref';
|
@@ -51,7 +52,7 @@ export class DropListRef<T = any> {
|
51 | 52 | private _document: Document;
|
52 | 53 |
|
53 | 54 | /** Element that the drop list is attached to. */
|
54 |
| - readonly element: HTMLElement; |
| 55 | + element: HTMLElement | ElementRef<HTMLElement>; |
55 | 56 |
|
56 | 57 | /**
|
57 | 58 | * Unique ID for the drop list.
|
@@ -224,7 +225,7 @@ export class DropListRef<T = any> {
|
224 | 225 | element.parentElement!.insertBefore(placeholder, element);
|
225 | 226 | activeDraggables.splice(newIndex, 0, item);
|
226 | 227 | } else {
|
227 |
| - this.element.appendChild(placeholder); |
| 228 | + coerceElement(this.element).appendChild(placeholder); |
228 | 229 | activeDraggables.push(item);
|
229 | 230 | }
|
230 | 231 |
|
@@ -416,7 +417,7 @@ export class DropListRef<T = any> {
|
416 | 417 |
|
417 | 418 | /** Caches the position of the drop list. */
|
418 | 419 | private _cacheOwnPosition() {
|
419 |
| - this._clientRect = this.element.getBoundingClientRect(); |
| 420 | + this._clientRect = coerceElement(this.element).getBoundingClientRect(); |
420 | 421 | }
|
421 | 422 |
|
422 | 423 | /** Refreshes the position cache of the items and sibling containers. */
|
@@ -607,21 +608,23 @@ export class DropListRef<T = any> {
|
607 | 608 | return false;
|
608 | 609 | }
|
609 | 610 |
|
610 |
| - const elementFromPoint = this._document.elementFromPoint(x, y); |
| 611 | + const elementFromPoint = this._document.elementFromPoint(x, y) as HTMLElement | null; |
611 | 612 |
|
612 | 613 | // If there's no element at the pointer position, then
|
613 | 614 | // the client rect is probably scrolled out of the view.
|
614 | 615 | if (!elementFromPoint) {
|
615 | 616 | return false;
|
616 | 617 | }
|
617 | 618 |
|
| 619 | + const nativeElement = coerceElement(this.element); |
| 620 | + |
618 | 621 | // The `ClientRect`, that we're using to find the container over which the user is
|
619 | 622 | // hovering, doesn't give us any information on whether the element has been scrolled
|
620 | 623 | // out of the view or whether it's overlapping with other containers. This means that
|
621 | 624 | // we could end up transferring the item into a container that's invisible or is positioned
|
622 | 625 | // below another one. We use the result from `elementFromPoint` to get the top-most element
|
623 | 626 | // at the pointer position and to find whether it's one of the intersecting drop containers.
|
624 |
| - return elementFromPoint === this.element || this.element.contains(elementFromPoint); |
| 627 | + return elementFromPoint === nativeElement || nativeElement.contains(elementFromPoint); |
625 | 628 | }
|
626 | 629 |
|
627 | 630 | /**
|
|
0 commit comments