Skip to content

Commit 85b85d2

Browse files
Ben RubinBen Rubin
authored andcommitted
add single select click
1 parent 78e9819 commit 85b85d2

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/js/branch.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,27 +280,24 @@ function branchController($scope, $mdUtil, $animateCss) {
280280
// toggel branch
281281
if (e.target.classList.contains('md-branch-icon-container')) {
282282
toggleBranchClick(e);
283-
e.stopPropagation();
284283
return;
285284
}
286285

287286
// handle select
288287
var isSelect = $element.attr('select') !== undefined;
289288
if (isSelect && branchContainsElement(e.target)) {
290289
var selected = $element.attr('selected') !== undefined;
291-
getTreeCtrl().toggleSelect(!selected, getTreeCtrl().hashGetter($scope[$scope.repeatName]), $scope[$scope.repeatName]);
292-
293290
$element.attr('selected', !selected);
294-
if (e.target.classList.contains('md-container')) { // clicked on checkbox
295-
// deselect all and select this branch
296-
} else {
297-
// if multiple is enabled add this to selection
298-
// otherwise single select
291+
292+
// deselect all if user did not click the checkbox
293+
if (!e.target.classList.contains('checkbox-container')) { // clicked on checkbox
294+
getTreeCtrl().deselectAll();
299295
}
296+
297+
getTreeCtrl().toggleSelect(!selected, getTreeCtrl().hashGetter($scope[$scope.repeatName]), $scope[$scope.repeatName]);
300298
e.stopPropagation();
301299
} else {
302300
toggleBranchClick(e);
303-
e.stopPropagation();
304301
}
305302
}
306303

@@ -316,6 +313,7 @@ function branchController($scope, $mdUtil, $animateCss) {
316313
if (!branchContainsElement(e.target)) { return; }
317314
if (isOpen !== true) { open(); }
318315
else { close(); }
316+
e.stopPropagation();
319317
}
320318

321319
function branchContainsElement(el) {

src/js/tree.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function treeDirective($mdTheming, $mdUtil) {
3939
vm.registerBranch = registerBranch;
4040
vm.unregisterBranch = unregisterBranch;
4141
vm.toggleSelect = toggleSelect;
42+
vm.deselectAll = deselectAll;
4243
vm.init = init;
4344
vm.hashGetter = hashGetter;
4445

@@ -109,6 +110,9 @@ function treeDirective($mdTheming, $mdUtil) {
109110
refreshViewValue();
110111
}
111112

113+
function deselectAll() {
114+
Object.keys(branches).forEach(deselect);
115+
}
112116

113117
function select(hashKey, hashedValue) {
114118
var branch = branches[hashKey];

src/style.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ md-branch.md-checkbox-enabled > .md-branch-inner {
304304

305305
// unchecked
306306
.checkbox-icon {
307+
pointer-events: none;
307308
box-sizing: border-box;
308309
transition: 240ms;
309310
position: absolute;

0 commit comments

Comments
 (0)