Search Result Box Won't Hide After Clicking Outside
PraveenShinde3 opened this issue · comments
Praveen Shinde commented
Search Result Box Won't Hide After Clicking Outside
Description
The search result box remains visible even after clicking outside of it. This issue affects the user experience by cluttering the interface and potentially causing confusion.
Steps to Reproduce
- Type a query into the search bar.
- Observe the search results box appearing below the search bar.
- Click anywhere outside the search results box.
Expected Behavior
The search result box should hide when clicking outside of it.
Expected-Example.webm
example website : https://certificatehub.vercel.app/
Actual Behavior
The search result box remains visible despite clicking outside of it.
Actual.webm
Suggested Fix
Implement an event listener to detect clicks outside the search result box and hide it accordingly.
const [isVisible, setIsVisible] = useState(false);
const ref = useRef(null);
const handleClickOutside = (event) => {
if (ref.current && !ref.current.contains(event.target)) {
setIsVisible(false);
}
};