Update
This commit is contained in:
1 parent
ebb2d8a2ab
commit
0c9a87e8be
9 files changed
+2269
-946
No files matched your search
@@ -24,27 +24,24 @@ export default function Navbar() {
|
||||
setDropdownActive(!isDropdownActive);
|
||||
}
|
||||
|
||||
function useOutsideAlerter(ref) {
|
||||
useEffect(() => {
|
||||
/**
|
||||
* Alert if clicked on outside of element
|
||||
*/
|
||||
function handleClickOutside(event) {
|
||||
if (ref.current && !ref.current.contains(event.target)) {
|
||||
setActive(true);
|
||||
}
|
||||
}
|
||||
// Bind the event listener
|
||||
document.addEventListener("mousedown", handleClickOutside);
|
||||
return () => {
|
||||
// Unbind the event listener on clean up
|
||||
document.removeEventListener("mousedown", handleClickOutside);
|
||||
};
|
||||
}, [ref]);
|
||||
}
|
||||
|
||||
const wrapperRef = useRef(null);
|
||||
useOutsideAlerter(wrapperRef);
|
||||
|
||||
useEffect(() => {
|
||||
/**
|
||||
* Close the menu if clicked on outside of element
|
||||
*/
|
||||
function handleClickOutside(event) {
|
||||
if (wrapperRef.current && !wrapperRef.current.contains(event.target)) {
|
||||
setActive(true);
|
||||
}
|
||||
}
|
||||
// Bind the event listener
|
||||
document.addEventListener("mousedown", handleClickOutside);
|
||||
return () => {
|
||||
// Unbind the event listener on clean up
|
||||
document.removeEventListener("mousedown", handleClickOutside);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<nav className={`${styles.navbar} shadow-sm`}>
|
||||
|
||||
Reference in new issue
Block a user