From 53132e64a84ad3f4369e91c56f46ea09a27f50ee Mon Sep 17 00:00:00 2001 From: Hari Dev Date: Tue, 24 Dec 2024 11:33:20 +0530 Subject: [PATCH] fix: Modifications in dropdown and networkcard clickevent --- frontend/src/components/Dropdown.jsx | 18 ++++++++++++++++-- frontend/src/components/NetworkCard.jsx | 23 +++++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) 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 (
-