Skip to content

Commit

Permalink
Preserve OverflowMenu style, change triggerPosition bounding element
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhabib committed Nov 27, 2024
1 parent 433268f commit 23793e5
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const MenuRenderer = ({
data,
...restProps
}: MenuRendererProps) => {
const menuContainerRef = useRef<HTMLButtonElement>(null);
const buttonRef = useRef<HTMLButtonElement>(null);
const lastOpen = useRef(false);
const items = flattenChildren(children);
Expand All @@ -154,7 +155,8 @@ export const MenuRenderer = ({
open: true,
closeReason: CLOSE_REASON_EXIT,
highlightIndex: getNextIndex(-1, state.highlightIndex, itemCount),
triggerPosition: buttonRef && getPosition(buttonRef.current),
triggerPosition:
menuContainerRef && getPosition(menuContainerRef.current),
};
}
case MENU_TRIGGER_DOWN:
Expand All @@ -164,7 +166,8 @@ export const MenuRenderer = ({
open: true,
closeReason: CLOSE_REASON_EXIT,
highlightIndex: getNextIndex(1, state.highlightIndex, itemCount),
triggerPosition: buttonRef && getPosition(buttonRef.current),
triggerPosition:
menuContainerRef && getPosition(menuContainerRef.current),
};
}
case BACKDROP_CLICK:
Expand Down Expand Up @@ -209,7 +212,8 @@ export const MenuRenderer = ({
open: nextOpen,
closeReason: CLOSE_REASON_EXIT,
highlightIndex: nextOpen ? 0 : CLOSED_INDEX,
triggerPosition: buttonRef && getPosition(buttonRef.current),
triggerPosition:
menuContainerRef && getPosition(menuContainerRef.current),
};
}
case MENU_TRIGGER_CLICK: {
Expand All @@ -219,13 +223,15 @@ export const MenuRenderer = ({
...state,
open: nextOpen,
closeReason: CLOSE_REASON_EXIT,
triggerPosition: buttonRef && getPosition(buttonRef.current),
triggerPosition:
menuContainerRef && getPosition(menuContainerRef.current),
};
}
case WINDOW_RESIZE: {
return {
...state,
triggerPosition: buttonRef && getPosition(buttonRef.current),
triggerPosition:
menuContainerRef && getPosition(menuContainerRef.current),
};
}
default:
Expand Down Expand Up @@ -334,7 +340,7 @@ export const MenuRenderer = ({

return (
<Box {...buildDataAttributes({ data, validateRestProps: restProps })}>
<Box position="relative">
<Box position="relative" ref={menuContainerRef}>
{trigger(triggerProps, { open })}

{open && (
Expand Down

0 comments on commit 23793e5

Please sign in to comment.