diff --git a/src/infinite-tree.js b/src/infinite-tree.js index 8a56617..683a938 100644 --- a/src/infinite-tree.js +++ b/src/infinite-tree.js @@ -673,6 +673,12 @@ class InfiniteTree extends events.EventEmitter { this.emit('willCloseNode', node); + // Cannot close the root node + if (node === this.state.rootNode) { + error('Cannot close the root node'); + return false; + } + // Retrieve node index const nodeIndex = this.nodes.indexOf(node); if (nodeIndex < 0) { @@ -1311,7 +1317,9 @@ class InfiniteTree extends events.EventEmitter { // Update parent node parentNode.children = []; - parentNode.state.open = parentNode.state.open && (parentNode.children.length > 0); + if (parentNode !== this.state.rootNode) { + parentNode.state.open = parentNode.state.open && (parentNode.children.length > 0); + } if (parentNodeIndex >= 0) { // Update nodes & rows @@ -1395,7 +1403,9 @@ class InfiniteTree extends events.EventEmitter { // Update parent node parentNode.children.splice(parentNode.children.indexOf(node), 1); - parentNode.state.open = parentNode.state.open && (parentNode.children.length > 0); + if (parentNode !== this.state.rootNode) { + parentNode.state.open = parentNode.state.open && (parentNode.children.length > 0); + } if (nodeIndex >= 0) { // Update nodes & rows