minop1205 / react-dnd-treeview

A draggable / droppable React-based treeview component. You can use render props to create each node freely.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

max depth

aydozgeee opened this issue · comments

Hello,
I added drag and drop feature to my project using dnd tree. I want the tree to have a max depth of 1. (i.e. there can only be one folder in a folder).I don't want it to be dropable when greater than that. how can I do it?

You can find the structure that I want to achieve in the attachment..

xtdndtree
?

@punisher28 Thanks for your comment!

I have had a similar Issue in the past, please refer to this one.
#62

If you are unable to resolve the issue, please reopen it.

Hello @minop1205,
Thanks for your reply. I checked the solution that you shared but it was not the exact solution that I am looking for. After a bit of digging, I come up with a solution below. I will be happy if you share your thoughts about the solution.

https://codesandbox.io/s/otupwe

@punisher28 The sample you provided is fine also.

I think it can be implemented a bit simpler, since we only need to know the depth of the dropTarget and the type of dragSource in the canDrop callback. Would this sample be helpful?

https://codesandbox.io/s/issue-127-fkfi1y?file=/src/App.jsx