diff --git a/src/types.ts b/src/types.ts index adf6842..450fd07 100644 --- a/src/types.ts +++ b/src/types.ts @@ -6,6 +6,7 @@ import React from "react"; export type NodeModel = { id: number | string; parent: number | string; + hasChildren: boolean; text: string; droppable?: boolean; data?: T; diff --git a/src/utils/hasChildNodes.ts b/src/utils/hasChildNodes.ts index 1f43b85..d02b872 100644 --- a/src/utils/hasChildNodes.ts +++ b/src/utils/hasChildNodes.ts @@ -4,5 +4,8 @@ export const hasChildNodes = ( tree: NodeModel[], nodeId: NodeModel["id"] ): boolean => { - return tree.some((node) => node.parent === nodeId); + return ( + tree.find((node) => node.id === nodeId)?.hasChildren || + tree.some((node) => node.parent === nodeId) + ); };