fix(react-menu): prevent focusing trigger on first mount if menu has been opened previously #34966
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.
This PR takes care of React 19 e2e integration test failures for the Menu component. The other 5 failures are being sorted out in a separate PR (#34985) since they don’t need any changes to the component runtime.
Previous Behavior
In React 19, MenuTrigger components were automatically focusing themselves when mounted or after re-renders, breaking accessibility expectations and failing e2e tests:
Root Cause
React 19 changed the timing of effect execution, causing the focus restoration logic in
useMenu.tsx
to trigger inappropriately when menus were closed but had never been opened.New Behavior
Added a
hasBeenOpenedRef
to track whether the menu has ever been opened. Focus restoration now only occurs when:!firstMount
)hasBeenOpenedRef.current
)Testing
Related Issue(s)