Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Autocomplete: Added check to prevent accidental focus of menu-item on…

… page load in Firefox. Fixed #7024 - Autocomplete menu options are activated even if mouse is not moved
  • Loading branch information...
commit 79aeb45363567a93afa2d45614c781561011b8e5 1 parent c0f6b0c
@kborchers authored
Showing with 17 additions and 0 deletions.
  1. +17 −0 ui/jquery.ui.autocomplete.js
View
17 ui/jquery.ui.autocomplete.js
@@ -57,6 +57,7 @@ $.widget( "ui.autocomplete", {
this.isMultiLine = this.element.is( "textarea,[contenteditable]" );
this.valueMethod = this.element[ this.element.is( "input,textarea" ) ? "val" : "text" ];
+ this.isNewMenu = true;
this.element
.addClass( "ui-autocomplete-input" )
@@ -224,6 +225,18 @@ $.widget( "ui.autocomplete", {
}
},
menufocus: function( event, ui ) {
+ // Prevent accidental activation of menu items in Firefox
+ if ( this.isNewMenu ) {
+ this.isNewMenu = false;
+ this.menu.blur();
+
+ $( document ).one( "mousemove", function( event ) {
+ $( event.target ).closest( ".ui-menu-item" ).mouseenter();
+ });
+
+ return;
+ }
+
// back compat for _renderItem using item.autocomplete, via #7810
// TODO remove the fallback, see #8156
var item = ui.item.data( "ui-autocomplete-item" ) || ui.item.data( "item.autocomplete" );
@@ -411,6 +424,7 @@ $.widget( "ui.autocomplete", {
if ( this.menu.element.is(":visible") ) {
this.menu.element.hide();
this.menu.blur();
+ this.isNewMenu = true;
this._trigger( "close", event );
}
},
@@ -457,6 +471,7 @@ $.widget( "ui.autocomplete", {
}, this.options.position ));
if ( this.options.autoFocus ) {
+ this.isNewMenu = false;
this.menu.next( new $.Event("mouseover") );
}
},
@@ -512,6 +527,8 @@ $.widget( "ui.autocomplete", {
_keyEvent: function( keyEvent, event ) {
if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
+ this.isNewMenu = false;
+
this._move( keyEvent, event );
// prevents moving cursor to beginning/end of the text field in some browsers

0 comments on commit 79aeb45

Please sign in to comment.
Something went wrong with that request. Please try again.