Skip to content

Commit

Permalink
Unsets lastSelectedNode if that node is deselected
Browse files Browse the repository at this point in the history
  • Loading branch information
viveleroi committed Feb 8, 2024
1 parent e9dc81d commit 8247932
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/treenode.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ class TreeNode {

baseStateChange('selected', false, 'deselected', this, deep);

if (this._tree._lastSelectedNode === this) {
this._tree._lastSelectedNode = null;
}

this.context().end();
}

Expand Down
18 changes: 17 additions & 1 deletion test/tree/lastSelectedNode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ describe('Tree.lastSelectedNode', function() {
}, {
text: 'B',
id: 2
}]
}],
selection: {
autoDeselect: false,
multiple: true
}
});
});

Expand All @@ -36,4 +40,16 @@ describe('Tree.lastSelectedNode', function() {

expect(tree.lastSelectedNode().id).to.equal(2);
});

it('returns last selected node even when another node is deselected', function() {
tree.node(1).deselect();

expect(tree.lastSelectedNode().id).to.equal(2);
});

it('returns null if last selected node is deselected', function() {
tree.node(2).deselect();

expect(tree.lastSelectedNode()).to.be.null;
});
});

0 comments on commit 8247932

Please sign in to comment.