Skip to content

Conversation

LFDanLu
Copy link
Member

@LFDanLu LFDanLu commented Aug 1, 2025

Closes RSP Component Milestones (view)

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

RSP

also makes it so ArrowRight still moves to the submenu after hovering, not sure if this breaks VO moving focus to the dismiss button though...
Comment on lines +134 to +137
[MenuContext, {
ref: submenuRef,
...submenuProps
}],
Copy link
Member Author

@LFDanLu LFDanLu Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes ArrowRight moving focus into the SubMenu after hovering it. Might cause iOS VO to close the submenu prematurely when focusing the dismiss button

EDIT: seems ok on my iPad but that is only on 17 since it is too old

@rspbot
Copy link

rspbot commented Aug 1, 2025

@LFDanLu
Copy link
Member Author

LFDanLu commented Aug 1, 2025

The other bug where all the submenus don't close when hovering the root menu item is a bit tricker. It broke due to the change to ignore blur/focus events bubbling through the portal via https://github.com/adobe/react-spectrum/blame/8f6724f09621327d78f77c997d6c7423e06b7b84/packages/%40react-aria/interactions/src/useFocusWithin.ts#L77-L81 which seems correct as a general change. However, this means we need to know to close all submenus up to a certain level without relying on useOverlay's onBlurWithin which used to handle this due to said bubbling (aka the outer most submenu's blur would bubble through each level all the way down).

Most solutions will need to provide the root menu state to menu items in general I think which is kinda gross... Would allow us to essentially do something like "if focus lands on a regular menu item, close all submenus that have a level greater than said menu item." Might be nice to have additional information on the item node for this. Alternatively, we can special case the ignoring of blur/focus event bubbling through portals strictly for submenus. This seems to work but unsure what side effects this might have

EDIT: Fixed, see PR change

this fixes the case where the user hovers a root menu level item when there are multiple submenu levels open but only the last one closes
@LFDanLu LFDanLu changed the title fix: (WIP) Make submenu hover focus remain on the trigger and collapse submenus when hovering root menu fix: Make submenu hover focus remain on the trigger and collapse submenus when hovering root menu Aug 5, 2025
@LFDanLu LFDanLu marked this pull request as ready for review August 5, 2025 22:35
@rspbot
Copy link

rspbot commented Aug 5, 2025

@rspbot
Copy link

rspbot commented Aug 5, 2025

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested in Chrome, working as expected

// Skip this for submenus since hovering a submenutrigger should keep focus on the trigger
useEffect(() => {
if (isDialog && ref.current && !ref.current.contains(document.activeElement)) {
if (isDialog && props.trigger !== 'SubmenuTrigger' && ref.current && !ref.current.contains(document.activeElement)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-/
I see we use this check in a few places though, so I'm ok with it. at some point we'll need to make this a more generic/defined behaviour check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit unfortunate for sure

[MenuItemContext, {...submenuTriggerProps, onAction: undefined, ref: itemRef}],
[MenuContext, submenuProps],
[MenuContext, {
ref: submenuRef,
Copy link
Member

@snowystinger snowystinger Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i assume this was just correcting a mistake? or was this necessary so we don't include submenus in the parentMenuRef check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just something we forgot to update I believe when we moved to automatically making these menus wrapped in dialogs. This resulted in the ref being passed to useSubmenuTrigger resolving to the dialog instead of the submenu, thus meaning ArrowRight wouldnt cause focus to move to the first menu item since we weren't actually focusing the menu.

@LFDanLu LFDanLu added this pull request to the merge queue Aug 6, 2025
Merged via the queue into main with commit 8b0e7d7 Aug 6, 2025
32 checks passed
@LFDanLu LFDanLu deleted the submenu_bugs branch August 6, 2025 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants