Skip to content

Commit 2445e20

Browse files
spekaryscottgonzalez
authored andcommitted
Autocomplete: Making sure we do not show search menu after a blur. Fixed #7423 - Tab out of autocomplete with remote source can leave menu showing.
1 parent 54fb144 commit 2445e20

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

tests/unit/autocomplete/autocomplete_events.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,25 @@ asyncTest( "cancel select", function() {
157157
}, 50 );
158158
});
159159

160+
asyncTest( "blur during remote search", function() {
161+
expect( 1 );
162+
var ac = $( "#autocomplete" ).autocomplete({
163+
delay: 0,
164+
source: function( request, response ) {
165+
ok( true, "trigger request" );
166+
ac.simulate( "blur" );
167+
setTimeout(function() {
168+
response([ "result" ]);
169+
start();
170+
}, 100 );
171+
},
172+
open: function() {
173+
ok( false, "opened after a blur" );
174+
}
175+
});
176+
ac.val( "ro" ).keydown();
177+
});
178+
160179
/* TODO previous fix broke more than it fixed, disabling this for now - messed up regular menu select event
161180
test("blur without selection", function() {
162181
expect(1);

ui/jquery.ui.autocomplete.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ $.widget( "ui.autocomplete", {
184184
}
185185

186186
clearTimeout( self.searching );
187+
self.cancelSearch = true;
187188
// clicks on the menu (or a button to trigger a search) will cause a blur event
188189
self.closing = setTimeout(function() {
189190
self.close( event );
@@ -373,6 +374,7 @@ $.widget( "ui.autocomplete", {
373374
_search: function( value ) {
374375
this.pending++;
375376
this.element.addClass( "ui-autocomplete-loading" );
377+
this.cancelSearch = false;
376378

377379
this.source( { term: value }, this.response );
378380
},
@@ -382,7 +384,7 @@ $.widget( "ui.autocomplete", {
382384
content = this._normalize( content );
383385
}
384386
this._trigger( "response", null, { content: content } );
385-
if ( !this.options.disabled && content && content.length ) {
387+
if ( !this.options.disabled && content && content.length && !this.cancelSearch ) {
386388
this._suggest( content );
387389
this._trigger( "open" );
388390
} else {

0 commit comments

Comments
 (0)