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

Docs on drop target `linearIndex` vs `childIndex` #211

Open holloway opened 1 year ago

holloway commented 1 year ago

Is your feature request related to a problem? Please describe.

Are there any docs on how to implement drop handlers (<ControlledTreeEnvironment>), specifically on how the drop target types should be interpreted and what the difference between linearIndex and childIndex is?

lukasbach commented 1 year ago

Hey! At the moment, there are no dedicated docs for that. The gist is essentially just to implement the onDrop handler, you can use the implementation in the uncontrolled environment for that as reference, although it is a bit verbose and messy to be honest.

When the user is dropping an item, he is hovering over an ("target") item. The target type provides details where on that item that is:

Regarding linearIndex and childIndex: childIndex refers to the position of an item within its parent. linearIndex refers to the overall position of the item within the entire tree, would all items be laid out in a linear manner. As an example:

image

The item "Black" has the childIndex 2, and the linearIndex 5.

Hope that was helpful, let me know if anything else is unclear!

natetewelde commented 1 year ago

When trying to implement the way its done in the uncontrolled tree environment, I'm running into the issue of items not being iterable in the initial for loop?

lukasbach commented 1 year ago

When trying to implement the way its done in the uncontrolled tree environment, I'm running into the issue of items not being iterable in the initial for loop?

What do you mean? Can you provide the implementation for the handler that you used and a log output of what value the items property has?

natetewelde commented 1 year ago

I was actually able to get it to not throw the error. Just would like an example of how to implement a simple custom onDrop handler that mimics the behavior of the uncontrolled tree.

lukasbach commented 1 year ago

Ah okay. One example is the actual implementation of the uncontrolled tree, but I have to admit, that it is far from simple. Unfortunately, it has a lot of corner cases that it respects at the moment, so that is all I have as an example at the moment.