click outside handled
This commit is contained in:
parent
ab2e4e3e5f
commit
aecd8dcef5
|
|
@ -1,5 +1,5 @@
|
|||
// Modules
|
||||
import { useRef, useEffect } from 'react';
|
||||
import { useRef, useEffect } from "react";
|
||||
import { useLocation, Link } from "react-router-dom";
|
||||
|
||||
// Icons
|
||||
|
|
@ -20,14 +20,17 @@ const Nav = ({
|
|||
const refTrigger = useRef<any>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if(ref.current && refTrigger.current){
|
||||
window.addEventListener('click', (e:any) => {
|
||||
if(!e.target.contains(ref.current) && !e.target.contains(refTrigger.current)){
|
||||
if (ref.current && refTrigger.current) {
|
||||
window.addEventListener("click", (e: any) => {
|
||||
if (
|
||||
!e.target.contains(ref.current) &&
|
||||
!e.target.contains(refTrigger.current)
|
||||
) {
|
||||
setDropdown(false);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}, [setDropdown, ref])
|
||||
}, [setDropdown, ref]);
|
||||
|
||||
return (
|
||||
<nav className="nav">
|
||||
|
|
|
|||
Loading…
Reference in New Issue