CirclonGroup / angular-tree-component

A simple yet powerful tree component for Angular (>=2)
https://angular2-tree.readme.io/docs
MIT License
1.1k stars 492 forks source link

Allow drag and drop only if particular element is clicked (not anywhere in whole div) #922

Open poonamsinghlm opened 3 years ago

poonamsinghlm commented 3 years ago

How to prevent drag and drop from particular element in tree-root. For below html ,how to allow drag only if div with class "header" is clicked but prevent drag if class "body" is clicked.

Have tried dragstart event but it always shows event.target as first parent div(class "node-wrapper") dragStart: (tree: TreeModel, node: TreeNode, event: any) => { },

 <tree-root >
    <ng-template #treeNodeWrapperTemplate let-node let-index="index">
      <div class="node-wrapper" 
              (treeDrop)="node.onDrop($event)" [treeAllowDrop]="node.allowDrop" [treeDrag]="node"
               [treeDragEnabled]="node.allowDrag()" [class]="node.data.isLast?'ed-object-last':''">
        <div>
        <div>
        <div >       
          <div class="header">
            <object-header [node]="node">
            </object-header>
          </div>      
        <div class="body">
            <object-body [node]="node"> </object-body>
          </div>
        </div>
      </div>
    </ng-template>
  </tree-root>
liesahead commented 3 years ago

I suggest to try adding click event on .body element and stopPropagation there. Should work.