Shaddix / dnd-kit-sortable-tree

Tree component for React with ability to drag-and-drop items throughout the tree. Based on an example from dnd-kit (https://github.com/clauderic/dnd-kit).
MIT License
81 stars 22 forks source link

Feature Request: Callback for canHaveChildren for Root #24

Closed konrad-gerlach closed 1 year ago

konrad-gerlach commented 1 year ago

I would like to be able to restrict the movement of items within the tree conditionally. If a condition is met, I want elements to not be able to change their parent and only be sorted (i.e. their indices changed) within their current parent. While part of this can be accomplished using canHaveChildren, one can still always move items to the root (simply adding a top-level item does not fix the problem). While I can disable the actual movement in onItemsChanged, the preview is still shown at the top level. Ideally, I would like to have a callback to determine if a specific drag is valid and only then show the preview in that new position, otherwise the preview would remain in its previous position. If that is too difficult, is it possible to add a callback to SortableTree, which has the same effect as canHaveChildren but for the root?

konrad-gerlach commented 1 year ago

I took the liberty of developing the feature myself #25 . I hope you don't mind @Shaddix and can quickly review it.

Shaddix commented 1 year ago

Thanks a lot, I'm gonna merge it and publish a new version