diff --git a/src/components/commons/CustomTooltip/index.tsx b/src/components/commons/CustomTooltip/index.tsx index d0948373c3..1ffff646dd 100644 --- a/src/components/commons/CustomTooltip/index.tsx +++ b/src/components/commons/CustomTooltip/index.tsx @@ -1,10 +1,12 @@ import { ClickAwayListener, Tooltip, TooltipProps, useTheme } from "@mui/material"; -import { useRef, useState } from "react"; +import { Dispatch, SetStateAction, useEffect, useRef, useState } from "react"; import { useScreen } from "src/commons/hooks/useScreen"; interface Props extends TooltipProps { wOpacity?: boolean; + closeTooltip?: boolean; + setIsCloseTooltip?: Dispatch>; } export const CustomTooltip = (props: Props) => { @@ -15,6 +17,13 @@ export const CustomTooltip = (props: Props) => { const { isMobile } = useScreen(); const tooltipRef = useRef(null); + useEffect(() => { + if (props?.closeTooltip) { + setOpenTooltip(false); + props?.setIsCloseTooltip?.(false); + } + }, [props?.closeTooltip]); + const handleOpenTooltip = () => { setOpenTooltip(true); }; diff --git a/src/pages/NativeScriptsAndSC/Card.tsx b/src/pages/NativeScriptsAndSC/Card.tsx index 055c8144b9..e53cbe9bf7 100644 --- a/src/pages/NativeScriptsAndSC/Card.tsx +++ b/src/pages/NativeScriptsAndSC/Card.tsx @@ -17,6 +17,7 @@ const NativeScriptCard: React.FC<{ data: NativeScriptsList; hasBeforeAndAfter: b const theme = useTheme(); const containerRef = useRef(null); const [isOverflowing, setIsOverflowing] = useState(false); + const [isCloseAllTooltip, setIsCloseAllTooltip] = useState(false); useEffect(() => { const container = containerRef.current; @@ -28,6 +29,20 @@ const NativeScriptCard: React.FC<{ data: NativeScriptsList; hasBeforeAndAfter: b } }, [isOverflowing]); + useEffect(() => { + const onCloseWhenChangeTab = () => { + if (document.visibilityState === "visible") { + setIsCloseAllTooltip(true); + } + }; + + document.addEventListener("visibilitychange", onCloseWhenChangeTab); + + return () => { + document.removeEventListener("visibilitychange", onCloseWhenChangeTab); + }; + }, []); + return ( @@ -61,6 +76,8 @@ const NativeScriptCard: React.FC<{ data: NativeScriptsList; hasBeforeAndAfter: b return ( setIsCloseAllTooltip(true)} key={index} title={isOverflowing ? item.displayName || getShortHash(item.fingerprint) || "" : null} >