Skip to content

Commit fc093e9

Browse files
committed
Prevent autocomplete-menu from closing when clicking 'slowly', eg. a long mousedown. Fix for #5405 - Autocomplete: select event not triggered when mousedown duration > blur timeout
1 parent fcbf4c0 commit fc093e9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ui/jquery.ui.autocomplete.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ $.widget( "ui.autocomplete", {
9696
.bind( "blur.autocomplete", function( event ) {
9797
clearTimeout( self.searching );
9898
// clicks on the menu (or a button to trigger a search) will cause a blur event
99-
// TODO try to implement this without a timeout, see clearTimeout in search()
10099
self.closing = setTimeout(function() {
101100
self.close( event );
102101
self._change( event );
@@ -109,6 +108,13 @@ $.widget( "ui.autocomplete", {
109108
this.menu = $( "<ul></ul>" )
110109
.addClass( "ui-autocomplete" )
111110
.appendTo( "body", doc )
111+
// prevent the close-on-blur in case of a "slow" click on the menu (long mousedown)
112+
.mousedown(function() {
113+
// use another timeout to make sure the blur-event-handler on the input was already triggered
114+
setTimeout(function() {
115+
clearTimeout( self.closing );
116+
}, 13);
117+
})
112118
.menu({
113119
focus: function( event, ui ) {
114120
var item = ui.item.data( "item.autocomplete" );

0 commit comments

Comments
 (0)