lukasbach / react-complex-tree

Unopinionated Accessible Tree Component with Multi-Select and Drag-And-Drop
https://rct.lukasbach.com
MIT License
952 stars 77 forks source link

Allow dropping on all items, but target node should always be a folder? #219

Closed MarksCode closed 1 year ago

MarksCode commented 1 year ago

I want to let the user drag and drop a node onto any other node, but if the target node is not a folder, the target should instead be the target node's parent (This is how most file-pickers work). Unfortunately setting canDropOnNonFolder to true causes the uncontrolled tree environment to attempt rendering the dragged node as a child of the non-folder target node, so this doesn't work.

Does anyone know if this sort of behavior is possible?

lukasbach commented 1 year ago

You can use an Controlled Environment instead of an uncontrolled environment, there you can define the drop logic yourself. You can use the drop implementation of the uncontrolled environment as an example (the uncontrolled environment react component is just a wrapper around the controlled environment, so technically you can just copy its implementation and change the drag logic).

But the use case is definitely justified, I don't have time to look into this this week, but will look into this soon if it makes sense to support this straight from the library.

MarksCode commented 1 year ago

Thanks @lukasbach. I will wait until you implement this feature to continue transitioning my company's file-picker to use this library.

MarksCode commented 1 year ago

Hey @lukasbach. Just wondering if you have any estimate for this feature. Thanks!

lukasbach commented 1 year ago

Hey, sorry didn't get to look into this recently, but added this today and released this as of 2.1.0.

MarksCode commented 1 year ago

Looks like there's a bug if you drop a folder onto a child folder, both of them will disappear.