Skip to content

Commit 03f6c51

Browse files
committed
fixed unselect on second click causing problem for retaining selected node on digest
1 parent 8b68394 commit 03f6c51

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

angular-tree-control.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
});
249249
}
250250
if (scope.options.equality(scope.node, scope.selectedNode)) {
251-
scope.selectNodeLabel(scope.node);
251+
scope.selectedNode = scope.node;
252252
}
253253

254254
// create a scope for the transclusion, whos parent is the parent of the tree control

test/angular-tree-control-test.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,27 @@ describe('treeControl', function() {
223223
expect($rootScope.itemSelected).toHaveBeenCalledWith('node 1');
224224
});
225225

226-
it('should not invoke on-selection callback when item is re-selected', function () {
226+
it('should call on-selection callback on item unselection with undefined node', function () {
227227
$rootScope.treedata = createSubTree(2, 2);
228-
element = $compile('<treecontrol tree-model="treedata" on-selection="itemSelected(node.label)">{{node.label}}</treecontrol>')($rootScope);
228+
element = $compile('<treecontrol tree-model="treedata" on-selection="itemSelected(node)">{{node.label}}</treecontrol>')($rootScope);
229229
$rootScope.$digest();
230230

231231
$rootScope.itemSelected = jasmine.createSpy('itemSelected');
232232
element.find('li:eq(0) div').click();
233233
element.find('li:eq(0) div').click();
234-
expect($rootScope.itemSelected).toHaveBeenCalledWith('node 1');
235-
expect($rootScope.itemSelected.calls.length).toBe(1);
234+
expect($rootScope.itemSelected).toHaveBeenCalledWith($rootScope.treedata[0]);
235+
expect($rootScope.itemSelected).toHaveBeenCalledWith(undefined);
236+
expect($rootScope.itemSelected.calls.length).toBe(2);
237+
});
238+
239+
it('should un-select a node after second click', function () {
240+
$rootScope.treedata = createSubTree(2, 2);
241+
$rootScope.selectedItem = $rootScope.treedata[0];
242+
element = $compile('<treecontrol tree-model="treedata" selected-node="selectedItem">{{node.label}}</treecontrol>')($rootScope);
243+
$rootScope.$digest();
244+
245+
element.find('li:eq(0) div').click();
246+
expect($rootScope.selectedItem).toBeUndefined()
236247
});
237248

238249
it('should retain selection after full model refresh', function () {

0 commit comments

Comments
 (0)