Skip to content

Commit

Permalink
Separate context
Browse files Browse the repository at this point in the history
  • Loading branch information
r100-stack committed Mar 6, 2025
1 parent 5ef4eaf commit 325ddbc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/itwinui-react/src/core/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ export const Menu = React.forwardRef((props, ref) => {
...rest
} = props;

const menuContext = React.useContext(MenuContext);
const portal = portalProp ?? menuContext?.portal;
const menuPortalContext = React.useContext(MenuPortalContext);
const portal = portalProp ?? menuPortalContext;

const tree = useFloatingTree();
const nodeId = useFloatingNodeId();
Expand Down Expand Up @@ -327,9 +327,7 @@ export const Menu = React.forwardRef((props, ref) => {

return (
<>
<MenuContext.Provider
value={{ popoverGetItemProps, focusableElements, portal }}
>
<MenuContext.Provider value={{ popoverGetItemProps, focusableElements }}>
<PopoverOpenContext.Provider value={popover.open}>
{reference}
</PopoverOpenContext.Provider>
Expand Down Expand Up @@ -363,11 +361,16 @@ type PopoverGetItemProps = ({
>[0];
}) => ReturnType<ReturnType<typeof useInteractions>['getItemProps']>;

// ----------------------------------------------------------------------------

export const MenuContext = React.createContext<
| {
popoverGetItemProps: PopoverGetItemProps;
focusableElements: HTMLElement[];
portal: PortalProps['portal'];
}
| undefined
>(undefined);

export const MenuPortalContext = React.createContext<
PortalProps['portal'] | undefined
>(undefined);

0 comments on commit 325ddbc

Please sign in to comment.