Skip to content

Commit

Permalink
Fix #234
Browse files Browse the repository at this point in the history
Only try to focus the first label if labels exist, otherwise focus on
the first link in the header.

SHIFT+TAB in the filter input will close the menu to be consistent with
tab behavior elsewhere and to prevent losing cursor.

If there are no options and the user hits tab on the last header
element, the menu will close.
  • Loading branch information
mlh758 committed Jan 9, 2017
1 parent 4ee469b commit e43a12c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/jquery.multiselect.filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
e.preventDefault();
} else if(e.which === 27) {
elem.multiselect('instance').close();
} else if(e.which === 9 && e.shiftKey) {
elem.multiselect('close');
e.preventDefault();
} else if(e.altKey) {
switch(e.which) {
case 82:
Expand Down
17 changes: 16 additions & 1 deletion src/jquery.multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,19 @@
}

e.preventDefault();
}).delegate('a', 'keydown.multiselect', function(e) {
switch(e.which) {
case 27:
self.close();
break;
case 9:
var $target = $(e.target);
if((e.shiftKey && !$target.parent().prev().length && !self.header.find(".ui-multiselect-filter").length) || (!$target.parent().next().length && !self.labels.length && !e.shiftKey)) {
self.close();
e.preventDefault();
}
break;
}
});
},

Expand Down Expand Up @@ -716,8 +729,10 @@
var filter = this.header.find(".ui-multiselect-filter");
if(filter.length) {
filter.first().find('input').trigger('focus');
} else {
} else if(this.labels.length){
this.labels.filter(':not(.ui-state-disabled)').eq(0).trigger('mouseover').trigger('mouseenter').find('input').trigger('focus');
} else {
this.header.find('a').first().trigger('focus');
}


Expand Down

0 comments on commit e43a12c

Please sign in to comment.