Skip to content
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createRef, useEffect, useState } from "react";
import React, { createRef, useEffect, useMemo, useState } from "react";
import { Tooltip } from "@blueprintjs/core";
import { CellWrapper, TooltipContentWrapper } from "../TableStyledWrappers";
import type { CellAlignment, VerticalAlignment } from "../Constants";
Expand Down Expand Up @@ -34,6 +34,7 @@ export const Content = styled.span`
const WIDTH_OFFSET = 32;
const MAX_WIDTH = 500;
const TOOLTIP_OPEN_DELAY = 500;
const MAX_CHARS_ALLOWED_IN_TOOLTIP = 200;

function useToolTip(
children: React.ReactNode,
Expand All @@ -43,6 +44,13 @@ function useToolTip(
const ref = createRef<HTMLDivElement>();
const [requiresTooltip, setRequiresTooltip] = useState(false);

const titleToDisplay = useMemo(() => {
Comment thread
rahulbarwal marked this conversation as resolved.
Outdated
if (title && title.length > MAX_CHARS_ALLOWED_IN_TOOLTIP) {
return `${title.substring(0, MAX_CHARS_ALLOWED_IN_TOOLTIP)} (...)`;
}
return title;
}, [title]);

useEffect(() => {
let timeout: ReturnType<typeof setTimeout>;

Expand Down Expand Up @@ -85,7 +93,7 @@ function useToolTip(
boundary="viewport"
content={
<TooltipContentWrapper width={MAX_WIDTH - WIDTH_OFFSET}>
{title}
{titleToDisplay}
</TooltipContentWrapper>
}
defaultIsOpen
Expand Down