Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu: Ignore mouse events triggered due to page scrolling #1806

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/unit/selectmenu/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is hacky, but simulate doesn't fill in realistic values for anything other than drag. We should update simulate and remove this, but that seemed a little out of scope for this PR.

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" );
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/selectmenu/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
14 changes: 14 additions & 0 deletions ui/widgets/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( {
Expand Down Expand Up @@ -116,6 +117,19 @@ return $.widget( "ui.menu", {
return;
}

// When the page is scrolled, a mousemove event is triggered because the mouse may
// be over a different element now. We don't want page scrolling to cause menu items
// to become active, so we need to detect this case and ignore it. (#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 );

Expand Down