Skip to content

Commit

Permalink
Fix an issue that could cause the root node to stay in the close state (
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Jun 1, 2018
1 parent 07cec31 commit 11f30fa
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/infinite-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 11f30fa

Please sign in to comment.