diff --git a/src/treenode.js b/src/treenode.js index cce08ff..65d3ccb 100644 --- a/src/treenode.js +++ b/src/treenode.js @@ -374,6 +374,10 @@ class TreeNode { baseStateChange('selected', false, 'deselected', this, deep); + if (this._tree._lastSelectedNode === this) { + this._tree._lastSelectedNode = null; + } + this.context().end(); } diff --git a/test/tree/lastSelectedNode.spec.js b/test/tree/lastSelectedNode.spec.js index 14b3b07..1ccb56c 100644 --- a/test/tree/lastSelectedNode.spec.js +++ b/test/tree/lastSelectedNode.spec.js @@ -13,7 +13,11 @@ describe('Tree.lastSelectedNode', function() { }, { text: 'B', id: 2 - }] + }], + selection: { + autoDeselect: false, + multiple: true + } }); }); @@ -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 undefined if last selected node is deselected', function() { + tree.node(2).deselect(); + + expect(tree.lastSelectedNode()).to.be.null; + }); });