fix(menu): prevent menu items from stealing focus on mouseover #5753
+221
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Problem
Menu items were stealing focus when users hovered over them, which caused several UX issues:
Solution
Changes Made
MenuItem.handleMouseover()
: Removedthis.focus()
call and replaced with hover trackingMenu
: ImplementedsetHoveredItem()
method to track hovered items without stealing focusTechnical Details
handleMouseover()
now callsthis.menuData.parentMenu?.setHoveredItem(this)
instead ofthis.focus()
hoveredItem
property andsetHoveredItem()
method for tracking hover stateFiles Changed:
packages/menu/src/MenuItem.ts
- Updated hover behaviorpackages/menu/src/Menu.ts
- Added hover tracking and keyboard transitionpackages/menu/test/menu.test.ts
- Updated tests for new behaviorMotivation and context
When users were typing in input fields (search, textfield, combobox, etc.) and accidentally hovered over menu items, focus would be stolen, interrupting their typing
Related issue(s)
Screenshots (if appropriate)
Author's checklist
Reviewer's checklist
patch
,minor
, ormajor
featuresManual review test cases
Test Case 1: Input Field Focus Preservation
Test Case 2: Keyboard Navigation After Hover
Tab
to focus the menu, then use arrow keys (↑
↓
)Enter
to select an itemTest Case 3: Menu Selection Behavior
Breaking Changes
None. This is a behavior improvement that maintains backward compatibility.
Device review