1- import { useEffect , useRef , useState } from "react" ;
1+ import React , { useEffect , useRef , useState } from "react" ;
22import useDetectMouseDownOutside from "../../../hooks/useDetectMouseDownOutside" ;
33import MenuItems , { MenuItemProps } from "../../MenuItems" ;
44
@@ -7,18 +7,24 @@ import { StyledAppMenu } from "./styles";
77export interface BorderedAppMenuProps {
88 title : string ;
99 items : Array < MenuItemProps > ;
10+ appRef : React . RefObject < HTMLDivElement > ;
1011}
1112
12- function BorderedAppMenu ( { title, items } : BorderedAppMenuProps ) {
13+ function BorderedAppMenu ( { title, appRef , items } : BorderedAppMenuProps ) {
1314 const [ open , setOpen ] = useState < boolean > ( false ) ;
1415 const elementRef = useRef < HTMLDivElement > ( null ) ;
1516 const position = useRef < { x : number ; y : number } > ( { x : 0 , y : 0 } ) ;
1617
1718 useEffect ( ( ) => {
1819 const rect = elementRef . current ?. getBoundingClientRect ( ) ;
19- // TODO: Look into where this -10 comes from
20- position . current = { x : ( rect ?. left ?? 0 ) - 10 , y : rect ?. height ?? 0 } ;
21- } , [ elementRef ] ) ;
20+ const appRect = appRef . current ?. getBoundingClientRect ( ) ;
21+ if ( ! rect || ! appRect ) return ;
22+
23+ position . current = {
24+ x : ( rect ?. left ?? 0 ) - appRect . left ,
25+ y : rect ?. height ?? 0 ,
26+ } ;
27+ } , [ appRef , elementRef ] ) ;
2228
2329 // Close the menu if an outside click occurs
2430 useDetectMouseDownOutside ( {
0 commit comments