dnd-kit-sortable-tree
dnd-kit-sortable-tree copied to clipboard
Disable on Tree item to have Children based on it's depth
Hello,
I have tried everything based on the configuration to disable a TreeItem to have children if depth is over or equal 2.
How you can achieve that?
I'm also interested in this feature
You can do the following:
const isValidDepth = (items: TreeItem<Group>[], currentDepth = 0): boolean => {
if (currentDepth >= MaxTreeDepth) {
return false;
}
return items.every(
(item) =>
!item.children?.length || isValidDepth(item.children, currentDepth + 1),
);
};
onItemsChanged={(newItems) => {
if (isValidDepth(newItems)) {
setItems(newItems);
}
}}