]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Ignore mouse events triggered due to page scrolling
authorScott González <scott.gonzalez@gmail.com>
Tue, 18 Apr 2017 20:51:23 +0000 (16:51 -0400)
committerScott González <scott.gonzalez@gmail.com>
Tue, 2 May 2017 19:16:17 +0000 (15:16 -0400)
Fixes #9356
Closes gh-1806

tests/unit/selectmenu/core.js
tests/unit/selectmenu/events.js
ui/widgets/menu.js

index cef6dc5bfd38af40bd10c0593434ab886443adcf..7084523127ad17a5c537d4681168fef823b6294a 100644 (file)
@@ -251,13 +251,13 @@ $.each( [
                        wrappers = menu.find( "li.ui-menu-item .ui-menu-item-wrapper" );
 
                        button.trigger( "click" );
-                       wrappers.first().simulate( "mouseover" ).trigger( "click" );
+                       wrappers.first().simulate( "mouseover", { clientX: 2, clientY: 2 } ).trigger( "click" );
                        assert.equal( element[ 0 ].selectedIndex, 0, "First item is selected" );
                        button.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
                        assert.equal( element[ 0 ].selectedIndex, 0, "No looping beyond first item" );
 
                        button.trigger( "click" );
-                       wrappers.last().simulate( "mouseover" ).trigger( "click" );
+                       wrappers.last().simulate( "mouseover", { clientX: 3, clientY: 3 } ).trigger( "click" );
                        assert.equal( element[ 0 ].selectedIndex, wrappers.length - 1, "Last item is selected" );
                        button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
                        assert.equal( element[ 0 ].selectedIndex, wrappers.length - 1, "No looping behind last item" );
index 4aed70ac80b64521e10a9aa9dc9af94c787c871d..ffc0429eede67967ae095ef696d40fcc2cbbe6ce 100644 (file)
@@ -89,9 +89,9 @@ QUnit.test( "focus", function( assert ) {
                button.trigger( "click" );
                links = menu.find( "li.ui-menu-item" );
                optionIndex = 0;
-               links.eq( optionIndex ).simulate( "mouseover" );
+               links.eq( optionIndex ).simulate( "mouseover", { clientX: 2, clientY: 2 } );
                optionIndex += 1;
-               links.eq( optionIndex ).simulate( "mouseover" );
+               links.eq( optionIndex ).simulate( "mouseover", { clientX: 3, clientY: 3 } );
 
                // This tests for unwanted, additional focus event on close
                that.element.selectmenu( "close" );
index 5df9d3eefd46b73bdb8fcb9eaa7b2bc87262bf6c..302d202ae1e3d5508fd1d2e66520f2b016c15cd3 100644 (file)
@@ -64,6 +64,7 @@ return $.widget( "ui.menu", {
                // Flag used to prevent firing of the click handler
                // as the event bubbles up through nested menus
                this.mouseHandled = false;
+               this.lastMousePosition = { x: null, y: null };
                this.element
                        .uniqueId()
                        .attr( {
@@ -161,6 +162,17 @@ return $.widget( "ui.menu", {
                        return;
                }
 
+               // If the mouse didn't actually move, but the page was scrolled, ignore the event (#9356)
+               if ( event.clientX === this.lastMousePosition.x &&
+                               event.clientY === this.lastMousePosition.y ) {
+                       return;
+               }
+
+               this.lastMousePosition = {
+                       x: event.clientX,
+                       y: event.clientY
+               };
+
                var actualTarget = $( event.target ).closest( ".ui-menu-item" ),
                        target = $( event.currentTarget );