|
71 | 71 | theme: 'bootstrap',
|
72 | 72 | searchEnabled: true,
|
73 | 73 | placeholder: '', // Empty by default, like HTML tag <select>
|
74 |
| - refreshDelay: 1000 // In milliseconds |
| 74 | + refreshDelay: 1000, // In milliseconds |
| 75 | + closeOnSelect: true |
75 | 76 | })
|
76 | 77 |
|
77 | 78 | // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913
|
|
166 | 167 | ctrl.tagging = {isActivated: false, fct: undefined};
|
167 | 168 | ctrl.taggingTokens = {isActivated: false, tokens: undefined};
|
168 | 169 | ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelect directive link function
|
| 170 | + ctrl.closeOnSelect = true; // Initialized inside uiSelect directive link function |
| 171 | + ctrl.clickTriggeredSelect = false; |
169 | 172 |
|
170 | 173 | ctrl.isEmpty = function() {
|
171 | 174 | return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === '';
|
|
346 | 349 | return isDisabled;
|
347 | 350 | };
|
348 | 351 |
|
| 352 | + |
349 | 353 | // When the user selects an item with ENTER or clicks the dropdown
|
350 |
| - ctrl.select = function(item, skipFocusser) { |
351 |
| - |
352 |
| - if ( ! ctrl.items && ! ctrl.search ) return; |
353 |
| - |
354 |
| - if (!item || !item._uiSelectChoiceDisabled) { |
355 |
| - if(ctrl.tagging.isActivated) { |
356 |
| - // if taggingLabel is disabled, we pull from ctrl.search val |
357 |
| - if ( ctrl.taggingLabel === false ) { |
358 |
| - if ( ctrl.activeIndex < 0 ) { |
359 |
| - item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; |
360 |
| - if ( angular.equals( ctrl.items[0], item ) ) { |
361 |
| - return; |
| 354 | + ctrl.select = function(item, skipFocusser, $event) { |
| 355 | + if (item === undefined || !item._uiSelectChoiceDisabled) { |
| 356 | + |
| 357 | + if ( ! ctrl.items && ! ctrl.search ) return; |
| 358 | + |
| 359 | + if (!item || !item._uiSelectChoiceDisabled) { |
| 360 | + if(ctrl.tagging.isActivated) { |
| 361 | + // if taggingLabel is disabled, we pull from ctrl.search val |
| 362 | + if ( ctrl.taggingLabel === false ) { |
| 363 | + if ( ctrl.activeIndex < 0 ) { |
| 364 | + item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; |
| 365 | + if ( angular.equals( ctrl.items[0], item ) ) { |
| 366 | + return; |
| 367 | + } |
| 368 | + } else { |
| 369 | + // keyboard nav happened first, user selected from dropdown |
| 370 | + item = ctrl.items[ctrl.activeIndex]; |
362 | 371 | }
|
363 | 372 | } else {
|
364 |
| - // keyboard nav happened first, user selected from dropdown |
365 |
| - item = ctrl.items[ctrl.activeIndex]; |
| 373 | + // tagging always operates at index zero, taggingLabel === false pushes |
| 374 | + // the ctrl.search value without having it injected |
| 375 | + if ( ctrl.activeIndex === 0 ) { |
| 376 | + // ctrl.tagging pushes items to ctrl.items, so we only have empty val |
| 377 | + // for `item` if it is a detected duplicate |
| 378 | + if ( item === undefined ) return; |
| 379 | + // create new item on the fly |
| 380 | + item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : item.replace(ctrl.taggingLabel,''); |
| 381 | + } |
366 | 382 | }
|
367 |
| - } else { |
368 |
| - // tagging always operates at index zero, taggingLabel === false pushes |
369 |
| - // the ctrl.search value without having it injected |
370 |
| - if ( ctrl.activeIndex === 0 ) { |
371 |
| - // ctrl.tagging pushes items to ctrl.items, so we only have empty val |
372 |
| - // for `item` if it is a detected duplicate |
373 |
| - if ( item === undefined ) return; |
374 |
| - // create new item on the fly |
375 |
| - item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : item.replace(ctrl.taggingLabel,''); |
| 383 | + // search ctrl.selected for dupes potentially caused by tagging and return early if found |
| 384 | + if ( ctrl.selected && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) { |
| 385 | + ctrl.close(skipFocusser); |
| 386 | + return; |
376 | 387 | }
|
377 | 388 | }
|
378 |
| - // search ctrl.selected for dupes potentially caused by tagging and return early if found |
379 |
| - if ( ctrl.selected && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) { |
380 |
| - ctrl.close(skipFocusser); |
381 |
| - return; |
382 |
| - } |
383 |
| - } |
384 | 389 |
|
385 |
| - var locals = {}; |
386 |
| - locals[ctrl.parserResult.itemName] = item; |
| 390 | + var locals = {}; |
| 391 | + locals[ctrl.parserResult.itemName] = item; |
387 | 392 |
|
388 |
| - ctrl.onSelectCallback($scope, { |
389 |
| - $item: item, |
390 |
| - $model: ctrl.parserResult.modelMapper($scope, locals) |
391 |
| - }); |
| 393 | + ctrl.onSelectCallback($scope, { |
| 394 | + $item: item, |
| 395 | + $model: ctrl.parserResult.modelMapper($scope, locals) |
| 396 | + }); |
392 | 397 |
|
393 |
| - if(ctrl.multiple){ |
394 |
| - ctrl.selected.push(item); |
395 |
| - ctrl.sizeSearchInput(); |
396 |
| - } else { |
397 |
| - ctrl.selected = item; |
| 398 | + if(ctrl.multiple) { |
| 399 | + ctrl.selected.push(item); |
| 400 | + ctrl.sizeSearchInput(); |
| 401 | + } else { |
| 402 | + ctrl.selected = item; |
| 403 | + } |
| 404 | + if (!ctrl.multiple || ctrl.closeOnSelect) { |
| 405 | + ctrl.close(skipFocusser); |
| 406 | + } |
| 407 | + if ($event && $event.type === 'click') { |
| 408 | + ctrl.clickTriggeredSelect = true; |
| 409 | + } |
398 | 410 | }
|
399 |
| - ctrl.close(skipFocusser); |
400 | 411 | }
|
401 | 412 | };
|
402 | 413 |
|
|
813 | 824 | var searchInput = element.querySelectorAll('input.ui-select-search');
|
814 | 825 |
|
815 | 826 | $select.multiple = (angular.isDefined(attrs.multiple)) ? (attrs.multiple === '') ? true : (attrs.multiple.toLowerCase() === 'true') : false;
|
816 |
| - |
| 827 | + $select.closeOnSelect = (angular.isDefined(attrs.closeOnSelect) && attrs.closeOnSelect.toLowerCase() === 'false') ? false : uiSelectConfig.closeOnSelect; |
817 | 828 | $select.onSelectCallback = $parse(attrs.onSelect);
|
818 | 829 | $select.onRemoveCallback = $parse(attrs.onRemove);
|
819 | 830 |
|
|
1051 | 1062 | contains = element[0].contains(e.target);
|
1052 | 1063 | }
|
1053 | 1064 |
|
1054 |
| - if (!contains) { |
| 1065 | + if (!contains && !$select.clickTriggeredSelect) { |
1055 | 1066 | $select.close();
|
1056 | 1067 | scope.$digest();
|
1057 | 1068 | }
|
| 1069 | + $select.clickTriggeredSelect = false; |
1058 | 1070 | }
|
1059 | 1071 |
|
1060 | 1072 | // See Click everywhere but here event http://stackoverflow.com/questions/12931369
|
|
1134 | 1146 | choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp))
|
1135 | 1147 | .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed
|
1136 | 1148 | .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')')
|
1137 |
| - .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ')'); |
| 1149 | + .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)'); |
1138 | 1150 |
|
1139 | 1151 | var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner');
|
1140 | 1152 | if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length);
|
|
0 commit comments