From 613c89312246ea8c485e2e55f46d0933566b8029 Mon Sep 17 00:00:00 2001 From: Umang Utkarsh Date: Sat, 9 Dec 2023 15:57:37 +0530 Subject: [PATCH] add-useffect --- client/modules/IDE/components/Sidebar.jsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/client/modules/IDE/components/Sidebar.jsx b/client/modules/IDE/components/Sidebar.jsx index c01815d339..01b84f8a4b 100644 --- a/client/modules/IDE/components/Sidebar.jsx +++ b/client/modules/IDE/components/Sidebar.jsx @@ -1,4 +1,4 @@ -import React, { useRef, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import classNames from 'classnames'; import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; @@ -67,6 +67,23 @@ export default function SideBar() { 'sidebar--cant-edit': !canEditProject }); + useEffect(() => { + const handleClickOutside = (event) => { + if ( + sidebarOptionsRef.current && + !sidebarOptionsRef.current.contains(event.target) + ) { + dispatch(closeProjectOptions()); + } + }; + + document.addEventListener('click', handleClickOutside); + + return () => { + document.removeEventListener('click', handleClickOutside); + }; + }, [dispatch]); + return ( {ide.sidebarIsExpanded && (