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

Commit 069c39a

Browse files
committed
fix(keys): should select active item and go to next control when pressing TAB
1 parent 299dacc commit 069c39a

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
@@ -182,6 +182,7 @@
182182
ctrl.activate = function(initSearchValue, avoidReset) {
183183
if (!ctrl.disabled && !ctrl.open) {
184184
if(!avoidReset) _resetSearchInput();
185+
ctrl.focusser.prop('disabled', true); //Will reactivate it on .close()
185186
ctrl.open = true;
186187
ctrl.activeMatchIndex = -1;
187188

@@ -319,7 +320,7 @@
319320
};
320321

321322
// When the user clicks on an item inside the dropdown
322-
ctrl.select = function(item) {
323+
ctrl.select = function(item, skipFocusser) {
323324

324325
if (item === undefined || !item._uiSelectChoiceDisabled) {
325326
var locals = {};
@@ -336,17 +337,19 @@
336337
} else {
337338
ctrl.selected = item;
338339
}
339-
ctrl.close();
340+
ctrl.close(skipFocusser);
340341
}
341342
};
342343

343344
// Closes the dropdown
344-
ctrl.close = function() {
345-
if (ctrl.open) {
345+
ctrl.close = function(skipFocusser) {
346+
if (!ctrl.open) return;
346347
_resetSearchInput();
347348
ctrl.open = false;
349+
if (!ctrl.multiple){
348350
$timeout(function(){
349-
ctrl.focusser[0].focus();
351+
ctrl.focusser.prop('disabled', false);
352+
if (!skipFocusser) ctrl.focusser[0].focus();
350353
},0,false);
351354
}
352355
};
@@ -403,8 +406,7 @@
403406
else if (ctrl.activeIndex > 0) { ctrl.activeIndex--; }
404407
break;
405408
case KEY.TAB:
406-
//TODO: Que hacemos en modo multiple?
407-
if (!ctrl.multiple) ctrl.select(ctrl.items[ctrl.activeIndex]);
409+
if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true);
408410
break;
409411
case KEY.ENTER:
410412
if(ctrl.open){

0 commit comments

Comments
 (0)