Skip to content
Open
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
22 changes: 19 additions & 3 deletions src/components/Tooltip/Tooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe("Tooltip", () => {
expect(screen.queryByTestId("tooltip-portal")).not.toBeInTheDocument();
});

it("renders tooltip message on focus", async () => {
it("shows tooltip message on focus", async () => {
render(
<Tooltip message="tooltip text">
<button>open the tooltip</button>
Expand All @@ -177,8 +177,24 @@ describe("Tooltip", () => {
await act(async () => {
await userEventWithTimers.tab();
});
expect(screen.getByTestId("tooltip-portal")).toBeInTheDocument();
expect(screen.getByText("tooltip text")).toBeInTheDocument();
expect(screen.getByTestId("tooltip-portal")).toBeVisible();
expect(screen.getByText("tooltip text")).toBeVisible();
});

it("shows tooltip message on focus, with followMouse active", async () => {
render(
<Tooltip message="tooltip text" followMouse>
<button>open the tooltip</button>
</Tooltip>,
);

expect(screen.queryByTestId("tooltip-portal")).not.toBeInTheDocument();
expect(screen.queryByText("tooltip text")).not.toBeInTheDocument();
await act(async () => {
await userEventWithTimers.tab();
});
expect(screen.getByTestId("tooltip-portal")).toBeVisible();
expect(screen.getByText("tooltip text")).toBeVisible();
});

it("updates the tooltip to fit on the screen", async () => {
Expand Down
16 changes: 14 additions & 2 deletions src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@
);

// Handle mouse events.
useListener(

Check failure on line 251 in src/components/Tooltip/Tooltip.tsx

View workflow job for this annotation

GitHub Actions / Lint, build and test

Replace `⏎····wrapperRef.current,⏎····mouseHandler,⏎····"mousemove",⏎····true,⏎····followMouse,⏎··` with `wrapperRef.current,·mouseHandler,·"mousemove",·true,·followMouse`
wrapperRef.current,
mouseHandler,
"mousemove",
true,
followMouse && isOpen,
followMouse,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
followMouse,
useListener(wrapperRef.current, mouseHandler, "mousemove", true, followMouse);

This whole block should be in a single line now.

);

// Handle adjusting the position of the tooltip so that it remains on screen.
Expand Down Expand Up @@ -307,6 +307,18 @@
openPortal();
};

const handleFocus = () => {
if (followMouse) {

Check failure on line 311 in src/components/Tooltip/Tooltip.tsx

View workflow job for this annotation

GitHub Actions / Lint, build and test

Insert `··`
if (wrapperRef.current) {

Check failure on line 312 in src/components/Tooltip/Tooltip.tsx

View workflow job for this annotation

GitHub Actions / Lint, build and test

Insert `··`
// set initial position for the tooltip

Check failure on line 313 in src/components/Tooltip/Tooltip.tsx

View workflow job for this annotation

GitHub Actions / Lint, build and test

Insert `··`
setPositionStyle(

Check failure on line 314 in src/components/Tooltip/Tooltip.tsx

View workflow job for this annotation

GitHub Actions / Lint, build and test

Insert `··`
getPositionStyle(adjustedPosition, wrapperRef.current)

Check failure on line 315 in src/components/Tooltip/Tooltip.tsx

View workflow job for this annotation

GitHub Actions / Lint, build and test

Replace `········getPositionStyle(adjustedPosition,·wrapperRef.current)` with `··········getPositionStyle(adjustedPosition,·wrapperRef.current),`
);

Check failure on line 316 in src/components/Tooltip/Tooltip.tsx

View workflow job for this annotation

GitHub Actions / Lint, build and test

Insert `··`
}

Check failure on line 317 in src/components/Tooltip/Tooltip.tsx

View workflow job for this annotation

GitHub Actions / Lint, build and test

Replace `····` with `······`
}

Check failure on line 318 in src/components/Tooltip/Tooltip.tsx

View workflow job for this annotation

GitHub Actions / Lint, build and test

Insert `··`
Comment on lines +311 to +318
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (followMouse) {
if (wrapperRef.current) {
// set initial position for the tooltip
setPositionStyle(
getPositionStyle(adjustedPosition, wrapperRef.current)
);
}
}
if (followMouse && wrapperRef.current) {
// set initial position for the tooltip
setPositionStyle(getPositionStyle(adjustedPosition, wrapperRef.current));
}
openPortal();

A bit simpler and please use correct spacing and formatting.

openPortal();

Check failure on line 319 in src/components/Tooltip/Tooltip.tsx

View workflow job for this annotation

GitHub Actions / Lint, build and test

Insert `··`
}

const delayedOpenPortal: MouseEventHandler = useCallback(() => {
if (isOpen) {
return;
Expand All @@ -325,7 +337,7 @@
className={className}
onBlur={handleBlur}
onClick={handleClick}
onFocus={openPortal}
onFocus={handleFocus}
onMouseOut={handleBlur}
onMouseOver={delayedOpenPortal}
>
Expand Down
Loading