Skip to content

Commit fd78724

Browse files
committed
Fix #286
If present, the filter text box will be focused when the menu is opened. Hitting escape in the menu closes the widget like it does anywhere else now. Closing the widget focuses on the button, which fixes tab navigation.
1 parent f97b867 commit fd78724

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/jquery.multiselect.filter.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
// prevent the enter key from submitting the form / closing the widget
6868
if(e.which === 13) {
6969
e.preventDefault();
70+
} else if(e.which === 82 && e.altKey) {
71+
e.preventDefault();
72+
$(this).val('').trigger('input', '');
73+
} else if(e.which === 27) {
74+
elem.multiselect('instance').close();
7075
}
7176
},
7277
input: $.proxy(debounce(this._handler, opts.debounceMS), this),

src/jquery.multiselect.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,15 @@
629629
// positon
630630
this.position();
631631

632-
// select the first not disabled option
633-
// triggering both mouseover and mouseover because 1.4.2+ has a bug where triggering mouseover
634-
// will actually trigger mouseenter. the mouseenter trigger is there for when it's eventually fixed
635-
this.labels.filter(':not(.ui-state-disabled)').eq(0).trigger('mouseover').trigger('mouseenter').find('input').trigger('focus');
632+
633+
// select the first not disabled option or the filter input if available
634+
var filter = this.header.find(".ui-multiselect-filter");
635+
if(filter.length) {
636+
filter.first().find('input').trigger('focus');
637+
} else {
638+
this.labels.filter(':not(.ui-state-disabled)').eq(0).trigger('mouseover').trigger('mouseenter').find('input').trigger('focus');
639+
}
640+
636641

637642
button.addClass('ui-state-active');
638643
this._isOpen = true;
@@ -664,6 +669,7 @@
664669
this.button.removeClass('ui-state-active').trigger('blur').trigger('mouseleave');
665670
this._isOpen = false;
666671
this._trigger('close');
672+
this.button.trigger('focus');
667673
},
668674

669675
enable: function() {

0 commit comments

Comments
 (0)