dnd-kit-sortable-tree icon indicating copy to clipboard operation
dnd-kit-sortable-tree copied to clipboard

Disable on Tree item to have Children based on it's depth

Open xmdcode opened this issue 1 year ago • 2 comments

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?

xmdcode avatar Oct 08 '24 08:10 xmdcode

I'm also interested in this feature

matheusAle avatar Nov 28 '24 21:11 matheusAle

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);
  }
}}

oliviercperrier avatar Sep 09 '25 20:09 oliviercperrier