-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
MenuList's MenuItem steals focus when hovered, cannot override as a user #33836
base: master
Are you sure you want to change the base?
Conversation
… ability to override behavior.
📊 Bundle size reportUnchanged fixtures
|
Pull request demo site: URL |
@smhigley / @microsoft/teams as heads up. I believe @microsoft/teams owns this code -- will need an approval from them regarding it. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing major wrong with this PR - As I mentioned offline, just would like to first discuss the input/menu pattern more deeply with @smhigley first to understand if we can do anything better about this
This pull request has been automatically marked as stale because it was marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 5 days of this comment. Thank you for your contributions to Fluent UI! |
Please see #33818 for full detailed description.
Current Behavior
I'm seeing an issue where when a user has focus within the input box, if they hover over any of the
<MenuItem>
s then focus will immediately jump to the menu item. This is particularly unwanted behavior as input boxes can have lots of ongoing text, and when focus is reset to a menu item, pressing keys like "r" will trigger certain hotkeys (e.g. "Reload the window") which is particularly unwanted.Of note, this is the exact same issue that was fixed back in 2021 with
ContextualMenu
via this ticket: Ticket #20552. The fix here was thatContextualMenu
has adelayUpdateFocusOnHover
prop added that wasn't quite working, which was fixed from that ticket (PR here).I am looking for an ask to have it implemented in or a similar mechanism such that a user can opt in or out of the functionality that on-hover for MenuItems will automatically focus.
The code that is causing this auto-focus is here:
From useMenuItem.tsx on line 77. I've tested locally that when this block of code is commented out, the behavior is resolved and focus is no longer stolen away.
Proposed PR Fix
The expected behavior is that hovering over a menu item does not steal away focus from another active menu item. In this case, a user should be able to continue typing in the Input component while moving the mouse around their screen, without worry that focus would be stolen and any subsequent button presses would trigger browser hotkeys.
Two options here: First, we could do something similar to Ticket #20552., where a property
delayUpdateFocusOnHover
is added. The user would then saydelayUpdateFocusOnHover={true}
in their creation ofMenuItem
and it would enforce that hover does not take focus.Another option (that this PR is starting with) is a bit lighter-weight. It simply rearranges the call such that a user calling
e.preventDefault()
will work in preventing what FluentUI is doing. Before, it was calling focus() first and then the user'sprops.onMouseMove?.(event)
. Now, it would callonMouseMove
first, and thenfocus()
if it isn't prevented.As it stands before the PR, the code is like so:
props.onMouseMove()
is called after the focus() call, so it's too late to do anything. A way to fix this would be:Reproduction
https://stackblitz.com/edit/vprprnxa?file=src%2Fexample.tsx
Steps to reproduce