Skip to content

Commit

Permalink
fix: remove tooltip from dom tree while invisible
Browse files Browse the repository at this point in the history
Signed-off-by: Zxilly <[email protected]>
  • Loading branch information
Zxilly committed Jul 7, 2024
1 parent 029a047 commit e704405
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 31 deletions.
17 changes: 1 addition & 16 deletions ui/src/Tooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,23 @@ function getTestNode(): Entry {
};
}

it("tooltip should render correctly when visible", () => {
it("tooltip should render", () => {
const { getByText } = render(
<Tooltip
x={0}
y={0}
visible
node={getTestNode()}
/>,
);
expect(getByText("test")).toBeInTheDocument();
expect(getByText("test content")).toBeInTheDocument();
});

it("tooltip should not render when not visible", () => {
const r = render(
<Tooltip
x={0}
y={0}
visible={false}
node={getTestNode()}
/>,
);
// should have a tooltip-hidden class
expect(r.container.querySelector(".tooltip-hidden")).not.toBeNull();
});

it("tooltip should respond to position", () => {
const r = render(
<Tooltip
x={0}
y={0}
visible
node={getTestNode()}
/>,
);
Expand Down
4 changes: 1 addition & 3 deletions ui/src/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const Tooltip_marginY = 30;

export interface TooltipProps {
node?: Entry;
visible: boolean;
x: number;
y: number;
}
Expand All @@ -16,7 +15,6 @@ export const Tooltip: React.FC<TooltipProps>
x,
y,
node,
visible,
}) => {
const ref = useRef<HTMLDivElement>(null);
const [style, setStyle] = useState({});
Expand Down Expand Up @@ -56,7 +54,7 @@ export const Tooltip: React.FC<TooltipProps>
}, [x, y]);

return (
<div className={`tooltip ${visible ? "" : "tooltip-hidden"}`} ref={ref} style={style}>
<div className="tooltip" ref={ref} style={style}>
<div>{path}</div>
<pre>
{content}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/TreeMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function TreeMap({ entry }: TreeMapProps) {

return (
<>
<Tooltip visible={showTooltip} node={tooltipNode?.data} x={tooltipPosition[0]} y={tooltipPosition[1]} />
{showTooltip && <Tooltip node={tooltipNode?.data} x={tooltipPosition[0]} y={tooltipPosition[1]} />}
<svg xmlns="http://www.w3.org/2000/svg" viewBox={`0 0 ${width} ${height}`} ref={svgRef}>
{nodes}
</svg>
Expand Down
6 changes: 0 additions & 6 deletions ui/src/__snapshots__/Treemap.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13247,12 +13247,6 @@ ResultImpl {

exports[`treemap 2`] = `
<div>
<div
class="tooltip "
>
<div />
<pre />
</div>
<svg
viewBox="0 0 1024 768"
xmlns="http://www.w3.org/2000/svg"
Expand Down
5 changes: 0 additions & 5 deletions ui/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ svg {
color: var(--text-color);
}

.tooltip-hidden {
visibility: hidden;
opacity: 0;
}

.node {
cursor: pointer;
}

0 comments on commit e704405

Please sign in to comment.