Skip to content

Commit e43a12c

Browse files
committed
Fix #234
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.
1 parent 4ee469b commit e43a12c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/jquery.multiselect.filter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
e.preventDefault();
7070
} else if(e.which === 27) {
7171
elem.multiselect('instance').close();
72+
} else if(e.which === 9 && e.shiftKey) {
73+
elem.multiselect('close');
74+
e.preventDefault();
7275
} else if(e.altKey) {
7376
switch(e.which) {
7477
case 82:

src/jquery.multiselect.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,19 @@
467467
}
468468

469469
e.preventDefault();
470+
}).delegate('a', 'keydown.multiselect', function(e) {
471+
switch(e.which) {
472+
case 27:
473+
self.close();
474+
break;
475+
case 9:
476+
var $target = $(e.target);
477+
if((e.shiftKey && !$target.parent().prev().length && !self.header.find(".ui-multiselect-filter").length) || (!$target.parent().next().length && !self.labels.length && !e.shiftKey)) {
478+
self.close();
479+
e.preventDefault();
480+
}
481+
break;
482+
}
470483
});
471484
},
472485

@@ -716,8 +729,10 @@
716729
var filter = this.header.find(".ui-multiselect-filter");
717730
if(filter.length) {
718731
filter.first().find('input').trigger('focus');
719-
} else {
732+
} else if(this.labels.length){
720733
this.labels.filter(':not(.ui-state-disabled)').eq(0).trigger('mouseover').trigger('mouseenter').find('input').trigger('focus');
734+
} else {
735+
this.header.find('a').first().trigger('focus');
721736
}
722737

723738

0 commit comments

Comments
 (0)