Skip to content
Permalink
Browse files

Menu: Ignore mouse events triggered due to page scrolling

Fixes #9356
Closes gh-1806
  • Loading branch information
scottgonzalez committed May 2, 2017
1 parent 7d992ae commit 50efd6e1b063822c4a0ecb38f324ed3354f387c4
Showing with 16 additions and 4 deletions.
  1. +2 −2 tests/unit/selectmenu/core.js
  2. +2 −2 tests/unit/selectmenu/events.js
  3. +12 −0 ui/widgets/menu.js
@@ -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" );
@@ -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" );
@@ -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 );

0 comments on commit 50efd6e

Please sign in to comment.
You can’t perform that action at this time.