From 098dd1404b7b6025a5735495a91ca2b964c5cb3e Mon Sep 17 00:00:00 2001 From: kborchers Date: Fri, 18 May 2012 15:55:10 -0400 Subject: [PATCH] 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. --- ui/jquery.ui.autocomplete.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 8ab48ba03..685bbca11 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/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" ) @@ -220,6 +221,20 @@ $.widget( "ui.autocomplete", { } }, menufocus: function( event, ui ) { + // #7024 - Prevent accidental activation of menu items in Firefox + if ( this.isNewMenu ) { + this.isNewMenu = false; + if ( event.originalEvent && /^mouse/.test(event.originalEvent.type) ) { + this.menu.blur(); + + this.document.one( "mousemove", function() { + $( event.target ).trigger( event.originalEvent ); + }); + + 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" ); @@ -422,6 +437,7 @@ $.widget( "ui.autocomplete", { if ( this.menu.element.is(":visible") ) { this.menu.element.hide(); this.menu.blur(); + this.isNewMenu = true; this._trigger( "close", event ); } }, -- 2.39.5