Skip to content

Commit 8247932

Browse files
committed
Unsets lastSelectedNode if that node is deselected
1 parent e9dc81d commit 8247932

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/treenode.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ class TreeNode {
374374

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

377+
if (this._tree._lastSelectedNode === this) {
378+
this._tree._lastSelectedNode = null;
379+
}
380+
377381
this.context().end();
378382
}
379383

test/tree/lastSelectedNode.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ describe('Tree.lastSelectedNode', function() {
1313
}, {
1414
text: 'B',
1515
id: 2
16-
}]
16+
}],
17+
selection: {
18+
autoDeselect: false,
19+
multiple: true
20+
}
1721
});
1822
});
1923

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

3741
expect(tree.lastSelectedNode().id).to.equal(2);
3842
});
43+
44+
it('returns last selected node even when another node is deselected', function() {
45+
tree.node(1).deselect();
46+
47+
expect(tree.lastSelectedNode().id).to.equal(2);
48+
});
49+
50+
it('returns null if last selected node is deselected', function() {
51+
tree.node(2).deselect();
52+
53+
expect(tree.lastSelectedNode()).to.be.null;
54+
});
3955
});

0 commit comments

Comments
 (0)