Repository navigation
fix(menu): don't show focus ring when MenuItem is focused by hover - #4368
Open
udit (UditDewan) wants to merge 1 commit into
Open
udit (UditDewan) wants to merge 1 commit into
udit (UditDewan) wants to merge 1 commit into
Conversation
On hover, onHoverIn hides the focus ring and useHoverFocusEffect then focuses the item. onFocus decided whether the focus came from hover by reading pressable.state.focused, which is stale at that point, so it always re-enabled the focus ring. Track hover-initiated focus with a ref instead so onFocus sees it synchronously. Fixes microsoft#4083
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Platforms Impacted
Description of changes
Fixes #4083.
When the mouse hovers a
MenuItem,onHoverInhides the focus ring anduseHoverFocusEffectthen calls.focus()on the item.onFocustried to detect "this focus came from hover" by checking!pressable.state.focused, but that value is the pre-hover render's state, so the check always passed andonFocusre-enabled the focus ring, overwriting thefalsethatonHoverInhad just set. The result is a focus ring on hovered menu items.packages/components/Menu/src/MenuItem/useMenuItem.ts:isHoverFocus) set inonHoverIn. Refs are read synchronously, so they aren't affected by React not having re-rendered yet.onFocusconsumes the flag: if focus came from hover the ring stays hidden, otherwise (keyboard/programmatic focus) the ring is enabled as before.macOS is unaffected (it already uses the plain pressable handlers and never shows the ring).
Verification
src/MenuItem/useMenuItem.test.win32.tsxcovering:enableFocusRingfalsemainand pass with this change.yarn build,yarn lint,yarn testfor@fluentui-react-native/menu;yarn format:check.Pull request checklist
This PR has considered (when applicable):