Skip to content

Commit 420c99b

Browse files
committed
fix(cdk/drag-drop): allow using cdkDragRootElement w/ comment tag
1 parent d70faa0 commit 420c99b

File tree

1 file changed

+4
-2
lines changed
  • src/cdk/drag-drop/directives

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,11 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
330330

331331
/** Syncs the root element with the `DragRef`. */
332332
private _updateRootElement() {
333-
const element = this.element.nativeElement;
333+
const element = this.element.nativeElement as HTMLElement;
334+
// Comment tag doesn't have closest method, so use parent's one.
335+
const closestFn = element.closest || element.parentElement?.closest;
334336
const rootElement = this.rootElementSelector ?
335-
element.closest<HTMLElement>(this.rootElementSelector) : element;
337+
closestFn<HTMLElement>(this.rootElementSelector) : element;
336338

337339
if (rootElement && (typeof ngDevMode === 'undefined' || ngDevMode)) {
338340
assertElementNode(rootElement, 'cdkDrag');

0 commit comments

Comments
 (0)