|
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. |
@@ -209,7 +210,7 @@ export class DropListRef<T = any> { |
209 | 210 | element.parentElement!.insertBefore(placeholder, element); |
210 | 211 | this._activeDraggables.splice(newIndex, 0, item); |
211 | 212 | } else { |
212 | | - this.element.appendChild(placeholder); |
| 213 | + coerceElement(this.element).appendChild(placeholder); |
213 | 214 | this._activeDraggables.push(item); |
214 | 215 | } |
215 | 216 |
|
@@ -395,7 +396,7 @@ export class DropListRef<T = any> { |
395 | 396 |
|
396 | 397 | /** Caches the position of the drop list. */ |
397 | 398 | private _cacheOwnPosition() { |
398 | | - this._clientRect = this.element.getBoundingClientRect(); |
| 399 | + this._clientRect = coerceElement(this.element).getBoundingClientRect(); |
399 | 400 | } |
400 | 401 |
|
401 | 402 | /** Refreshes the position cache of the items and sibling containers. */ |
@@ -579,21 +580,23 @@ export class DropListRef<T = any> { |
579 | 580 | return false; |
580 | 581 | } |
581 | 582 |
|
582 | | - const elementFromPoint = this._document.elementFromPoint(x, y); |
| 583 | + const elementFromPoint = this._document.elementFromPoint(x, y) as HTMLElement | null; |
583 | 584 |
|
584 | 585 | // If there's no element at the pointer position, then |
585 | 586 | // the client rect is probably scrolled out of the view. |
586 | 587 | if (!elementFromPoint) { |
587 | 588 | return false; |
588 | 589 | } |
589 | 590 |
|
| 591 | + const nativeElement = coerceElement(this.element); |
| 592 | + |
590 | 593 | // The `ClientRect`, that we're using to find the container over which the user is |
591 | 594 | // hovering, doesn't give us any information on whether the element has been scrolled |
592 | 595 | // out of the view or whether it's overlapping with other containers. This means that |
593 | 596 | // we could end up transferring the item into a container that's invisible or is positioned |
594 | 597 | // below another one. We use the result from `elementFromPoint` to get the top-most element |
595 | 598 | // at the pointer position and to find whether it's one of the intersecting drop containers. |
596 | | - return elementFromPoint === this.element || this.element.contains(elementFromPoint); |
| 599 | + return elementFromPoint === nativeElement || nativeElement.contains(elementFromPoint); |
597 | 600 | } |
598 | 601 |
|
599 | 602 | /** |
|
0 commit comments