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

fix: Improve menu mouse/keyboard selection interaction. #8749

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

gonfunko
Copy link
Contributor

@gonfunko gonfunko commented Jan 27, 2025

The basics

The details

Resolves

Proposed Changes

This PR updates the menu to check if the pointer has actually moved before selecting the hovered menu item in response to an alleged pointer move event. Previously, it was listening for pointerover events, and selecting the hovered menu item. In the case where the user has their pointer over the menu, and is scrolling through the list of menu items via the up/down arrows, the menu items will scroll into view when the selection reaches the beginning/end of the visible set of menu items. This movement of elements under the pointer causes a pointerover event to fire, even though the pointer has been stationary, which had the effect of jumping the selection backwards to whatever menu item was under the pointer.

Although pointerover events have movementX/movementY properties, these are unpopulated (at least in Chrome), so I changed the code to listen for pointermove instead, which does populate them. This allows checking whether the event was triggered due to movement, and disregarding it if not.

Experimentally, this gives the desired behavior in Chrome/Safari/Firefox: moving the pointer highlights the corresponding menu items, but keyboard navigation takes precedence for navigating through menu items, until such time as the pointer is actually moved.

I also updated the field names to reference "pointer" instead of "mouse" since they were all private.

Additionally, this PR fixes an issue that caused menus to lose focus when the pointer exited their bounds.

@gonfunko gonfunko requested a review from a team as a code owner January 27, 2025 22:34
@gonfunko gonfunko requested a review from cpcallen January 27, 2025 22:34
@github-actions github-actions bot added the PR: fix Fixes a bug label Jan 27, 2025
@gonfunko gonfunko changed the title fix: Only highlight menu items on hover if the pointer has moved. fix: Improve menu mouse/keyboard selection interaction. Jan 27, 2025
@github-actions github-actions bot added PR: fix Fixes a bug and removed PR: fix Fixes a bug labels Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: fix Fixes a bug
Projects
None yet
2 participants