-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now the menu position is automatically recalculated depending on wher…
…e the parent element is located. Deleted an unused hook.
- Loading branch information
Showing
4 changed files
with
18 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import React, { useEffect, useRef } from "react"; | ||
|
||
export const useMenuPosition = ( | ||
elementRef: React.MutableRefObject<HTMLElement | HTMLDivElement | null> | ||
elementRef: React.RefObject<HTMLDivElement>, | ||
offsetTop: number, | ||
offsetLeft: number | ||
) => { | ||
const [menuPosition, setMenuPosition] = useState({ | ||
top: 0, | ||
left: 0, | ||
}); | ||
const menuRef = useRef<HTMLMenuElement>(null); | ||
|
||
useEffect(() => { | ||
if (elementRef.current) { | ||
const elementNode = elementRef.current; | ||
setMenuPosition({ | ||
top: elementNode.offsetTop, | ||
left: elementNode.offsetLeft, | ||
}); | ||
if (elementRef.current && menuRef.current) { | ||
const top = elementRef.current.offsetTop; | ||
const left = elementRef.current.offsetLeft; | ||
|
||
menuRef.current.style.top = top + offsetTop + "px"; | ||
menuRef.current.style.left = left + offsetLeft + "px"; | ||
} | ||
}, [elementRef]); | ||
}, [elementRef.current?.offsetTop, elementRef.current?.offsetLeft]); | ||
|
||
return menuPosition; | ||
return menuRef; | ||
}; |
This file was deleted.
Oops, something went wrong.