|
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.
|
@@ -227,7 +228,7 @@ export class DropListRef<T = any> {
|
227 | 228 | element.parentElement!.insertBefore(placeholder, element);
|
228 | 229 | activeDraggables.splice(newIndex, 0, item);
|
229 | 230 | } else {
|
230 |
| - this.element.appendChild(placeholder); |
| 231 | + coerceElement(this.element).appendChild(placeholder); |
231 | 232 | activeDraggables.push(item);
|
232 | 233 | }
|
233 | 234 |
|
@@ -413,7 +414,7 @@ export class DropListRef<T = any> {
|
413 | 414 |
|
414 | 415 | /** Caches the position of the drop list. */
|
415 | 416 | private _cacheOwnPosition() {
|
416 |
| - this._clientRect = this.element.getBoundingClientRect(); |
| 417 | + this._clientRect = coerceElement(this.element).getBoundingClientRect(); |
417 | 418 | }
|
418 | 419 |
|
419 | 420 | /** Refreshes the position cache of the items and sibling containers. */
|
@@ -597,21 +598,23 @@ export class DropListRef<T = any> {
|
597 | 598 | return false;
|
598 | 599 | }
|
599 | 600 |
|
600 |
| - const elementFromPoint = this._document.elementFromPoint(x, y); |
| 601 | + const elementFromPoint = this._document.elementFromPoint(x, y) as HTMLElement | null; |
601 | 602 |
|
602 | 603 | // If there's no element at the pointer position, then
|
603 | 604 | // the client rect is probably scrolled out of the view.
|
604 | 605 | if (!elementFromPoint) {
|
605 | 606 | return false;
|
606 | 607 | }
|
607 | 608 |
|
| 609 | + const nativeElement = coerceElement(this.element); |
| 610 | + |
608 | 611 | // The `ClientRect`, that we're using to find the container over which the user is
|
609 | 612 | // hovering, doesn't give us any information on whether the element has been scrolled
|
610 | 613 | // out of the view or whether it's overlapping with other containers. This means that
|
611 | 614 | // we could end up transferring the item into a container that's invisible or is positioned
|
612 | 615 | // below another one. We use the result from `elementFromPoint` to get the top-most element
|
613 | 616 | // at the pointer position and to find whether it's one of the intersecting drop containers.
|
614 |
| - return elementFromPoint === this.element || this.element.contains(elementFromPoint); |
| 617 | + return elementFromPoint === nativeElement || nativeElement.contains(elementFromPoint); |
615 | 618 | }
|
616 | 619 |
|
617 | 620 | /**
|
|
0 commit comments