Search code examples
javascriptreactjsantd

How to prevent drop on a particular node in Antd tree?


I am using Antd tree for my React application. I am using drag and drop feature of the tree. I have this requirement where I should prevent user from dropping the dragged nodes on certain nodes. Is there any droppable='false' kind of config available on tree node to prevent the drop on the node?


Solution

  • allowDrop property should be a function, its parameter is node and its output is Boolean: ({ dropNode, dropPosition }) => boolean this function executes for each node of your tree and base on output the node will be dropable or not.

    allowDrop = {(node, dropPosition) => {
      console.log(node, dropPosition);
      //add some funtionality
      return false; //return true/false base on funtionality
    }}