diff --git a/frontend/src/components/Dropdown.jsx b/frontend/src/components/Dropdown.jsx index 3e40df3..0efa236 100644 --- a/frontend/src/components/Dropdown.jsx +++ b/frontend/src/components/Dropdown.jsx @@ -1,18 +1,32 @@ -import React ,{useState}from "react"; +import React ,{useState , useEffect}from "react"; +import { useRef } from "react"; import "tailwindcss/tailwind.css"; const Dropdown = () => { const [visible, setVisible] = useState(false); + const dropdownRef = useRef(null); + // Function to handle the click event const handleClick = () => { setVisible(!visible); }; + // Function to handle the click outside the dropdown + const handleClickOutside = (event) => { + if (dropdownRef.current && !dropdownRef.current.contains(event.target)) + { setVisible(false); } }; + + // useEffect hook to add an event listener when the component mounts + useEffect(() => { + document.addEventListener('mousedown', handleClickOutside); + return () => { document.removeEventListener('mousedown', handleClickOutside); }; + }, []); + return (