Skip to content

Commit 4f23661

Browse files
committed
fix: append the ghost element to the body
1 parent 9d0f754 commit 4f23661

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/draggable.directive.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import {
99
OnDestroy,
1010
OnChanges,
1111
NgZone,
12-
SimpleChanges
12+
SimpleChanges,
13+
Inject
1314
} from '@angular/core';
15+
import { DOCUMENT } from '@angular/common';
1416
import { Subject, Observable, merge } from 'rxjs';
1517
import {
1618
map,
@@ -145,7 +147,8 @@ export class DraggableDirective implements OnInit, OnChanges, OnDestroy {
145147
public element: ElementRef<HTMLElement>,
146148
private renderer: Renderer2,
147149
private draggableHelper: DraggableHelper,
148-
private zone: NgZone
150+
private zone: NgZone,
151+
@Inject(DOCUMENT) private document: Document
149152
) {}
150153

151154
ngOnInit(): void {
@@ -236,10 +239,7 @@ export class DraggableDirective implements OnInit, OnChanges, OnDestroy {
236239
'visibility',
237240
'hidden'
238241
);
239-
this.element.nativeElement.parentNode!.insertBefore(
240-
clone,
241-
this.element.nativeElement.nextSibling
242-
);
242+
this.document.body.appendChild(clone);
243243
this.ghostElement = clone;
244244

245245
this.setElementStyles(clone, {
@@ -248,7 +248,6 @@ export class DraggableDirective implements OnInit, OnChanges, OnDestroy {
248248
left: `${rect.left}px`,
249249
width: `${rect.width}px`,
250250
height: `${rect.height}px`,
251-
zIndex: '1000',
252251
cursor: this.dragCursor,
253252
margin: '0'
254253
});

test/draggable.directive.spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,6 @@ describe('draggable directive', () => {
578578
expect(ghostElement.style.left).to.be.ok;
579579
expect(ghostElement.style.width).to.be.ok;
580580
expect(ghostElement.style.height).to.be.ok;
581-
expect(ghostElement.style.zIndex).to.equal('1000');
582581
expect(draggableElement.style.visibility).to.equal('hidden');
583582
expect((ghostElement as HTMLElement).hasAttribute('mwldraggable')).to.be
584583
.true;

0 commit comments

Comments
 (0)