-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: Make submenu hover focus remain on the trigger and collapse submenus when hovering root menu #8666
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
fix: Make submenu hover focus remain on the trigger and collapse submenus when hovering root menu #8666
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,10 +131,12 @@ export const SubmenuTrigger = /*#__PURE__*/ createBranchComponent('submenutrigg | |
<Provider | ||
values={[ | ||
[MenuItemContext, {...submenuTriggerProps, onAction: undefined, ref: itemRef}], | ||
[MenuContext, submenuProps], | ||
[MenuContext, { | ||
ref: submenuRef, | ||
...submenuProps | ||
}], | ||
Comment on lines
+134
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
[OverlayTriggerStateContext, submenuTriggerState], | ||
[PopoverContext, { | ||
ref: submenuRef, | ||
trigger: 'SubmenuTrigger', | ||
triggerRef: itemRef, | ||
placement: 'end top', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,11 +190,12 @@ function PopoverInner({state, isExiting, UNSTABLE_portalContainer, clearContexts | |
}, [ref, shouldBeDialog]); | ||
|
||
// Focus the popover itself on mount, unless a child element is already focused. | ||
// 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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :-/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a bit unfortunate for sure |
||
focusSafely(ref.current); | ||
} | ||
}, [isDialog, ref]); | ||
}, [isDialog, ref, props.trigger]); | ||
|
||
let children = useMemo(() => { | ||
let children = renderProps.children; | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
i assume this was just correcting a mistake? or was this necessary so we don't include submenus in the parentMenuRef check?
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.
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.