Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit a73be72

Browse files
committed
Merge pull request #286 from angular-ui/fix-select-with-tab
Should select active item and go to next control when pressing TAB
2 parents d2c6493 + 069c39a commit a73be72

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/select.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
ctrl.activate = function(initSearchValue, avoidReset) {
185185
if (!ctrl.disabled && !ctrl.open) {
186186
if(!avoidReset) _resetSearchInput();
187+
ctrl.focusser.prop('disabled', true); //Will reactivate it on .close()
187188
ctrl.open = true;
188189
ctrl.activeMatchIndex = -1;
189190

@@ -321,7 +322,7 @@
321322
};
322323

323324
// When the user clicks on an item inside the dropdown
324-
ctrl.select = function(item) {
325+
ctrl.select = function(item, skipFocusser) {
325326

326327
if (item === undefined || !item._uiSelectChoiceDisabled) {
327328
var locals = {};
@@ -338,17 +339,19 @@
338339
} else {
339340
ctrl.selected = item;
340341
}
341-
ctrl.close();
342+
ctrl.close(skipFocusser);
342343
}
343344
};
344345

345346
// Closes the dropdown
346-
ctrl.close = function() {
347-
if (ctrl.open) {
347+
ctrl.close = function(skipFocusser) {
348+
if (!ctrl.open) return;
348349
_resetSearchInput();
349350
ctrl.open = false;
351+
if (!ctrl.multiple){
350352
$timeout(function(){
351-
ctrl.focusser[0].focus();
353+
ctrl.focusser.prop('disabled', false);
354+
if (!skipFocusser) ctrl.focusser[0].focus();
352355
},0,false);
353356
}
354357
};
@@ -405,8 +408,7 @@
405408
else if (ctrl.activeIndex > 0) { ctrl.activeIndex--; }
406409
break;
407410
case KEY.TAB:
408-
//TODO: Que hacemos en modo multiple?
409-
if (!ctrl.multiple) ctrl.select(ctrl.items[ctrl.activeIndex]);
411+
if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true);
410412
break;
411413
case KEY.ENTER:
412414
if(ctrl.open){

0 commit comments

Comments
 (0)