Hi, can I limit the number of root nodes for react-sortable-tree? Also, can I limit the number of direct children that nodes can have?
I suppose you could create a custom canDrop prop that examines the nextPath to see if the length is 0 (meaning you're targeting the top level / root of the tree), as well as if your treeData array is already the max length or not.
You could solve your children-limiting logic in that same method, checking the length of nextParent.children.
Thanks, it's working - looks like this for anyone wondering (I instantiate a full tree before allowing editing):
<SortableTree
{...otherProps}
canDrop={({ nextParent,nextPath }) =>(!nextParent || !nextParent.noChildren) && nextPath.length>1 }
/>
Most helpful comment
I suppose you could create a custom
canDropprop that examines thenextPathto see if the length is 0 (meaning you're targeting the top level / root of the tree), as well as if yourtreeDataarray is already the max length or not.You could solve your children-limiting logic in that same method, checking the length of
nextParent.children.