From 4a275dd6339a39bdd445e230bc0f24d75f4c96b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yi=C4=9Fit=20FINDIKLI?= Date: Mon, 12 Apr 2021 17:05:09 +0300 Subject: [PATCH] Fixed ##10093 - [p-tree] event.accept() not available on first drop --- src/app/components/tree/tree.ts | 37 +++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/app/components/tree/tree.ts b/src/app/components/tree/tree.ts index d313b9c4384..ddb938e5497 100755 --- a/src/app/components/tree/tree.ts +++ b/src/app/components/tree/tree.ts @@ -513,7 +513,7 @@ export class UITreeNode implements OnInit {
+ (drop)="onDrop($event)" (dragover)="onDragOver($event)" (dragenter)="onDragEnter()" (dragleave)="onDragLeave($event)">
@@ -1028,30 +1028,45 @@ export class Tree implements OnInit,AfterContentInit,OnChanges,OnDestroy,Blockab if (this.droppableNodes && (!this.value || this.value.length === 0)) { event.preventDefault(); let dragNode = this.dragNode; + if (this.allowDrop(dragNode, null, this.dragNodeScope)) { let dragNodeIndex = this.dragNodeIndex; - this.dragNodeSubNodes.splice(dragNodeIndex, 1); this.value = this.value||[]; - if (this.value.length === 0) { + if (this.validateDrop) { + this.onNodeDrop.emit({ + originalEvent: event, + dragNode: dragNode, + dropNode: null, + index: dragNodeIndex, + accept: () => { + this.processTreeDrop(dragNode, dragNodeIndex); + } + }); + } + else { this.onNodeDrop.emit({ originalEvent: event, dragNode: dragNode, dropNode: null, index: dragNodeIndex - }) + }); + + this.processTreeDrop(dragNode, dragNodeIndex); } - - this.value.push(dragNode); - - this.dragDropService.stopDrag({ - node: dragNode - }); } } } - onDragEnter(event) { + processTreeDrop(dragNode, dragNodeIndex) { + this.dragNodeSubNodes.splice(dragNodeIndex, 1); + this.value.push(dragNode); + this.dragDropService.stopDrag({ + node: dragNode + }); + } + + onDragEnter() { if (this.droppableNodes && this.allowDrop(this.dragNode, null, this.dragNodeScope)) { this.dragHover = true; }