Skip to content

Commit

Permalink
Fix tooltip performances (#9930)
Browse files Browse the repository at this point in the history
Rendering the Tooltip is creating performance issues on the whole app.

In this PR we only render the tooltip on hover
  • Loading branch information
charlesBochet authored Jan 30, 2025
1 parent a039987 commit ae4bf8d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
3 changes: 3 additions & 0 deletions packages/twenty-ui/src/display/tooltip/AppTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type AppTooltipProps = {
positionStrategy?: PositionStrategy;
clickable?: boolean;
width?: string;
isOpen?: boolean;
};

export const AppTooltip = ({
Expand All @@ -65,6 +66,7 @@ export const AppTooltip = ({
children,
clickable,
width,
isOpen,
}: AppTooltipProps) => {
const delayInMs =
delay === TooltipDelay.noDelay
Expand All @@ -89,6 +91,7 @@ export const AppTooltip = ({
children,
clickable,
width,
isOpen,
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const OverflowingTextWithTooltip = ({
const textRef = useRef<HTMLDivElement>(null);

const [isTitleOverflowing, setIsTitleOverflowing] = useState(false);
const [shouldRenderTooltip, setShouldRenderTooltip] = useState(false);

const handleMouseEnter = () => {
const isOverflowing =
Expand All @@ -98,10 +99,12 @@ export const OverflowingTextWithTooltip = ({
: false;

setIsTitleOverflowing(isOverflowing);
setShouldRenderTooltip(true);
};

const handleMouseLeave = () => {
setIsTitleOverflowing(false);
setShouldRenderTooltip(false);
};

const handleTooltipClick = (event: React.MouseEvent<HTMLDivElement>) => {
Expand Down Expand Up @@ -137,26 +140,29 @@ export const OverflowingTextWithTooltip = ({
{text}
</StyledOverflowingText>
)}
{createPortal(
<div onClick={handleTooltipClick}>
<AppTooltip
anchorSelect={`#${textElementId}`}
offset={5}
hidden={!isTitleOverflowing || hideTooltip}
noArrow
place="bottom"
positionStrategy="absolute"
delay={TooltipDelay.mediumDelay}
>
{isTooltipMultiline ? (
<Styledpre>{text}</Styledpre>
) : (
`${text || ''}`
)}
</AppTooltip>
</div>,
document.body,
)}
{shouldRenderTooltip &&
isTitleOverflowing &&
createPortal(
<div onClick={handleTooltipClick}>
<AppTooltip
anchorSelect={`#${textElementId}`}
offset={5}
hidden={!isTitleOverflowing || hideTooltip}
noArrow
place="bottom"
positionStrategy="absolute"
delay={TooltipDelay.mediumDelay}
isOpen={true}
>
{isTooltipMultiline ? (
<Styledpre>{text}</Styledpre>
) : (
`${text || ''}`
)}
</AppTooltip>
</div>,
document.body,
)}
</>
);
};

0 comments on commit ae4bf8d

Please sign in to comment.