Skip to content

Conversation

Rajdeepc
Copy link
Contributor

@Rajdeepc Rajdeepc commented Sep 25, 2025

Description

Problem

Menu items were stealing focus when users hovered over them, which caused several UX issues:

  1. Input field disruption: When users were typing in input fields (search, textfield, combobox, etc.) and accidentally hovered over menu items, focus would be stolen, interrupting their typing
  2. Inconsistent behavior: Focus management was inconsistent between hover and keyboard navigation
  3. Accessibility concerns: Screen readers and keyboard users experienced unexpected focus changes

Solution

Changes Made

  1. Updated MenuItem.handleMouseover(): Removed this.focus() call and replaced with hover tracking
  2. Added hover tracking in Menu: Implemented setHoveredItem() method to track hovered items without stealing focus
  3. Enhanced keyboard listener: Added global keyboard listener to enable smooth transition from hover to keyboard navigation

Technical Details

  • MenuItem.ts: handleMouseover() now calls this.menuData.parentMenu?.setHoveredItem(this) instead of this.focus()
  • Menu.ts: Added hoveredItem property and setHoveredItem() method for tracking hover state
  • Focus management: When users press arrow keys after hovering, focus transitions smoothly to the hovered item
  • Global keyboard listener: Automatically cleans up when keyboard navigation begins

Files Changed:

  • packages/menu/src/MenuItem.ts - Updated hover behavior
  • packages/menu/src/Menu.ts - Added hover tracking and keyboard transition
  • packages/menu/test/menu.test.ts - Updated tests for new behavior

Motivation 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)

  • fixes SWC-1027

Screenshots (if appropriate)


Author's checklist

  • I have read the CONTRIBUTING and PULL_REQUESTS documents.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices
  • I have added automated tests to cover my changes.
  • I have included a well-written changeset if my change needs to be published.
  • I have included updated documentation if my change required it.

Reviewer's checklist

  • Includes a Github Issue with appropriate flag or Jira ticket number without a link
  • Includes thoughtfully written changeset if changes suggested include patch, minor, or major features
  • Automated tests cover all use cases and follow best practices for writing
  • Validated on all supported browsers
  • All VRTs are approved before the author can update Golden Hash

Manual review test cases

  • Test Case 1: Input Field Focus Preservation

    1. Go to
    2. Focus the input field and start typing
    3. Hover over menu items while typing
    4. Expected: Focus remains in input field, typing continues uninterrupted
    5. Failure: Focus jumps to menu items, typing stops
  • Test Case 2: Keyboard Navigation After Hover

    1. Go to
    2. Hover over different menu items
    3. Press Tab to focus the menu, then use arrow keys ( )
    4. Press Enter to select an item
    5. Expected: Smooth transition from hover to keyboard navigation, selection works
    6. Failure: Arrow keys don't work, focus doesn't transition properly
  • Test Case 3: Menu Selection Behavior

    1. Go to
    2. Click on different menu items
    3. Expected: Selection changes correctly on click
    4. Failure: Clicking doesn't change selection

Breaking Changes

None. This is a behavior improvement that maintains backward compatibility.

Device review

  • Did it pass in Desktop?
  • Did it pass in (emulated) Mobile?
  • Did it pass in (emulated) iPad?

Copy link

changeset-bot bot commented Sep 25, 2025

⚠️ No Changeset found

Latest commit: 425cab1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Rajdeepc Rajdeepc self-assigned this Sep 25, 2025
Copy link
Contributor

github-actions bot commented Sep 25, 2025

📚 Branch Preview

🔍 Visual Regression Test Results

When a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:

Deployed to Azure Blob Storage: pr-5753

If the changes are expected, update the current_golden_images_cache hash in the circleci config to accept the new images. Instructions are included in that file.
If the changes are unexpected, you can investigate the cause of the differences and update the code accordingly.

Copy link
Contributor

Tachometer results

Currently, no packages are changed by this PR...

@Rajdeepc
Copy link
Contributor Author

Submenus are flaky. WIP

@Rajdeepc Rajdeepc added the WIP label Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant