Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/react-aria-components/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {UNSTABLE_useSubmenuTrigger} from '@react-aria/menu';
export const MenuContext = createContext<ContextValue<MenuProps<any>, HTMLDivElement>>(null);
export const MenuStateContext = createContext<TreeState<unknown> | null>(null);
export const RootMenuTriggerStateContext = createContext<RootMenuTriggerState | null>(null);
export const SubmenuContext = createContext<{popoverContainerRef: RefObject<Element>} | null>(null);

export interface MenuTriggerProps extends BaseMenuTriggerProps {
children?: ReactNode
Expand Down Expand Up @@ -181,7 +180,8 @@ function MenuInner<T extends object>({props, collection, menuRef: ref}: MenuInne
values={[
[MenuStateContext, state],
[SeparatorContext, {elementType: 'div'}],
[SubmenuContext, {popoverContainerRef}]
// eslint-disable-next-line rulesdir/pure-render
[PopoverContext, {UNSTABLE_portalContainer: popoverContainerRef.current || undefined}]
]}>
{children}
</Provider>
Expand Down Expand Up @@ -349,7 +349,6 @@ function MenuItemTriggerInner<T>({item, popover, parentMenuRef, delay}: MenuItem
let state = useContext(MenuStateContext)!;
let ref = useObjectRef<any>(item.props.ref);
let rootMenuTriggerState = useContext(RootMenuTriggerStateContext)!;
let submenuContext = useContext(SubmenuContext)!;
let submenuTriggerState = UNSTABLE_useSubmenuTriggerState({triggerKey: item.key}, rootMenuTriggerState);
let submenuRef = useRef<HTMLDivElement>(null);
let {submenuTriggerProps, submenuProps, popoverProps} = UNSTABLE_useSubmenuTrigger({
Expand Down Expand Up @@ -398,7 +397,6 @@ function MenuItemTriggerInner<T>({item, popover, parentMenuRef, delay}: MenuItem
trigger: 'SubmenuTrigger',
triggerRef: ref,
placement: 'end top',
UNSTABLE_portalContainer: submenuContext.popoverContainerRef.current || undefined,
Copy link
Member

Choose a reason for hiding this comment

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

Oh should UNSTABLE_portalContainer really be UNSTABLE_portalContainerRef?

Copy link
Member

Choose a reason for hiding this comment

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

Then we'd pass the ref itself? instead of taking current out?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was released in December, so I think it would be breaking? #5381

Copy link
Member Author

Choose a reason for hiding this comment

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

We could add a new UNSTABLE_portalContainerRef prop and try to use that first.

Copy link
Member

Choose a reason for hiding this comment

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

oh, for some reason I thought we only just added it

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it was recently added to RSP

Copy link
Member

Choose a reason for hiding this comment

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

it is technically UNSTABLE, so i don't think changing it would count as a breaking change. however, I still think we should only do it if absolutely necessary

...popoverProps
}]
]}>
Expand Down
3 changes: 2 additions & 1 deletion packages/react-aria-components/test/Menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ describe('Menu', () => {
expect(nestedSubmenuPopover).toHaveAttribute('data-trigger', 'SubmenuTrigger');

// Click a nested submenu item
await user.click(getAllByRole('menuitem')[8]);
await user.click(getAllByRole('menuitem')[5]);
expect(onAction).toHaveBeenLastCalledWith('work');
expect(nestedSubmenu).not.toBeInTheDocument();
expect(submenu).not.toBeInTheDocument();
Expand Down Expand Up @@ -671,6 +671,7 @@ describe('Menu', () => {
expect(document.activeElement).toBe(button);
});
it('should restore focus to menu trigger if nested submenu is closed with Escape key', async () => {
document.elementFromPoint = jest.fn().mockImplementation(query => query);
let {getByRole, getAllByRole} = render(
<MenuTrigger>
<Button aria-label="Menu">☰</Button>
Expand Down