Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ADAE-1800 hide tooltip when change tab #3035

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/commons/CustomTooltip/index.tsx
Original file line number Diff line number Diff line change
@@ -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<SetStateAction<boolean>>;
}

export const CustomTooltip = (props: Props) => {
Expand All @@ -15,6 +17,13 @@ export const CustomTooltip = (props: Props) => {
const { isMobile } = useScreen();
const tooltipRef = useRef<HTMLDivElement>(null);

useEffect(() => {
if (props?.closeTooltip) {
setOpenTooltip(false);
props?.setIsCloseTooltip?.(false);
}
}, [props?.closeTooltip]);

const handleOpenTooltip = () => {
setOpenTooltip(true);
};
Expand Down
17 changes: 17 additions & 0 deletions src/pages/NativeScriptsAndSC/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const NativeScriptCard: React.FC<{ data: NativeScriptsList; hasBeforeAndAfter: b
const theme = useTheme();
const containerRef = useRef<HTMLDivElement>(null);
const [isOverflowing, setIsOverflowing] = useState(false);
const [isCloseAllTooltip, setIsCloseAllTooltip] = useState(false);

useEffect(() => {
const container = containerRef.current;
Expand All @@ -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 (
<Item>
<Box p={2} height={"100%"} display={"block"} component={Link} to={details.nativeScriptDetail(data.scriptHash)}>
Expand Down Expand Up @@ -61,6 +76,8 @@ const NativeScriptCard: React.FC<{ data: NativeScriptsList; hasBeforeAndAfter: b
return (
<Box
component={isOverflowing ? CustomTooltip : Box}
closeTooltip={isCloseAllTooltip}
setIsCloseTooltip={() => setIsCloseAllTooltip(true)}
key={index}
title={isOverflowing ? item.displayName || getShortHash(item.fingerprint) || "" : null}
>
Expand Down
Loading