Skip to content

Commit 5a24ee0

Browse files
committed
Selectmenu: Override menu's _closeOnDocumentClick function to prevent collapseAll and manually fix focus state on open
1 parent ec61e54 commit 5a24ee0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ui/jquery.ui.selectmenu.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,13 @@ $.widget( "ui.selectmenu", {
149149
// adjust menu styles to dropdown
150150
this.menu.addClass( "ui-corner-bottom" ).removeClass( "ui-corner-all" );
151151

152-
// Make sure focus stays on selected item
153-
this.menuInstance.delay = 999999999;
154152
// Unbind uneeded Menu events
155153
this.menuInstance._off( this.menu, "mouseleave" );
154+
155+
// Cancel the menu's collapseAll on document click
156+
this.menuInstance._closeOnDocumentClick = function() {
157+
return false;
158+
};
156159
},
157160

158161
refresh: function() {
@@ -185,9 +188,13 @@ $.widget( "ui.selectmenu", {
185188
if ( this.options.disabled ) {
186189
return;
187190
}
191+
188192
// Support: IE6-IE9 click doesn't trigger focus on the button
189193
if ( !this.menuItems ) {
190194
this.refresh();
195+
} else {
196+
this.menu.find( ".ui-state-focus" ).removeClass( "ui-state-focus" );
197+
this.menu.menu( "focus", null, this._getSelectedItem() );
191198
}
192199

193200
this.isOpen = true;
@@ -198,7 +205,7 @@ $.widget( "ui.selectmenu", {
198205

199206
this._trigger( "open", event );
200207
},
201-
208+
202209
_position: function() {
203210
this.menuWrap.position( $.extend( { of: this.button }, this.options.position ) );
204211
},

0 commit comments

Comments
 (0)