Skip to content

Commit 3ccc49c

Browse files
authored
fix(tooltip): change show/hide behavior to work with links in description (#2501)
fix(tooltip): change show/hide behavior to work with embedded contents Signed-off-by: Adam Setch <[email protected]>
1 parent 20ef001 commit 3ccc49c

File tree

11 files changed

+135
-118
lines changed

11 files changed

+135
-118
lines changed

src/renderer/components/fields/Tooltip.test.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,33 @@ describe('renderer/components/fields/Tooltip.tsx', () => {
1313
it('should render', () => {
1414
renderWithAppContext(<Tooltip {...props} />);
1515

16-
expect(screen.getByTestId('tooltip-test')).toBeInTheDocument();
16+
expect(screen.getByTestId('tooltip-icon-test')).toBeInTheDocument();
17+
expect(screen.queryByText(props.tooltip as string)).not.toBeInTheDocument();
18+
});
19+
20+
it('should toggle (show/hide) tooltip on clicking tooltip icon', async () => {
21+
renderWithAppContext(<Tooltip {...props} />);
22+
23+
const tooltipIconElement = screen.getByTestId('tooltip-icon-test');
24+
25+
await userEvent.click(tooltipIconElement);
26+
expect(screen.queryByText(props.tooltip as string)).toBeInTheDocument();
27+
28+
await userEvent.click(tooltipIconElement);
29+
expect(screen.queryByText(props.tooltip as string)).not.toBeInTheDocument();
1730
});
1831

19-
it('should display on mouse enter / leave', async () => {
32+
it('should hide tooltip contents on leave', async () => {
2033
renderWithAppContext(<Tooltip {...props} />);
2134

22-
const tooltipElement = screen.getByTestId('tooltip-test');
35+
const tooltipIconElement = screen.getByTestId('tooltip-icon-test');
2336

24-
await userEvent.hover(tooltipElement);
37+
await userEvent.click(tooltipIconElement);
2538
expect(screen.queryByText(props.tooltip as string)).toBeInTheDocument();
2639

27-
await userEvent.unhover(tooltipElement);
40+
const tooltipContentElement = screen.getByTestId('tooltip-content-test');
41+
42+
await userEvent.unhover(tooltipContentElement);
2843
expect(screen.queryByText(props.tooltip as string)).not.toBeInTheDocument();
2944
});
3045
});

src/renderer/components/fields/Tooltip.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ export const Tooltip: FC<TooltipProps> = (props: TooltipProps) => {
2121
<button
2222
{...anchorProps}
2323
aria-label={props.name}
24-
data-testid={`tooltip-${props.name}`}
24+
data-testid={`tooltip-icon-${props.name}`}
2525
id={props.name}
26-
onMouseEnter={() => setShowTooltip(true)}
27-
onMouseLeave={() => setShowTooltip(false)}
26+
onClick={() => setShowTooltip(!showTooltip)}
2827
type="button"
2928
>
3029
<QuestionIcon className="text-gitify-tooltip-icon" />
@@ -38,6 +37,9 @@ export const Tooltip: FC<TooltipProps> = (props: TooltipProps) => {
3837
'text-left text-xs text-gitify-font',
3938
'rounded-sm border border-gray-300 shadow-sm bg-gitify-tooltip-popout',
4039
)}
40+
data-testid={`tooltip-content-${props.name}`}
41+
onMouseLeave={() => setShowTooltip(false)}
42+
role="tooltip"
4143
>
4244
{props.tooltip}
4345
</div>

src/renderer/components/fields/__snapshots__/Checkbox.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/components/filters/__snapshots__/FilterSection.test.tsx.snap

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)