Skip to content

Commit

Permalink
Fix missing default Tooltip delay (#2263)
Browse files Browse the repository at this point in the history
  • Loading branch information
r100-stack authored Sep 26, 2024
1 parent 6639cb9 commit aaa0e3e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-avocados-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': patch
---

Default `Tooltip` delay is now correctly applied.
1 change: 1 addition & 0 deletions apps/react-workshop/src/Breadcrumbs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('Breadcrumbs', () => {
cy.get('button').eq(1).click();
} else if (testName === 'Custom Overflow Back Button') {
cy.get('button').eq(1).trigger('mouseenter');
cy.wait(60);
}

cy.compareSnapshot(testName);
Expand Down
13 changes: 6 additions & 7 deletions packages/itwinui-react/src/core/Slider/Slider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { act, fireEvent, render } from '@testing-library/react';
import { act, fireEvent, render, waitFor } from '@testing-library/react';
import { Slider } from './Slider.js';
import { userEvent } from '@testing-library/user-event';

Expand Down Expand Up @@ -503,14 +503,13 @@ it('should show tooltip on thumb hover', async () => {
expect(thumb.classList).not.toContain('iui-active');
expect(document.querySelector('.iui-tooltip')).toBeNull();

vi.useFakeTimers();
fireEvent.mouseEnter(thumb);
act(() => void vi.advanceTimersByTime(50));
vi.useRealTimers();

const tooltip = document.querySelector('.iui-tooltip');
expect(tooltip).toBeVisible();
expect(tooltip).toHaveTextContent('50');
await waitFor(() => {
const tooltip = document.querySelector('.iui-tooltip');
expect(tooltip).toBeVisible();
expect(tooltip).toHaveTextContent('50');
});
});

it('should show tooltip on thumb focus', async () => {
Expand Down
22 changes: 8 additions & 14 deletions packages/itwinui-react/src/core/Tooltip/Tooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { act, fireEvent, render } from '@testing-library/react';
import { act, fireEvent, render, waitFor } from '@testing-library/react';
import * as React from 'react';
import { Tooltip } from './Tooltip.js';

it('should toggle the visibility of tooltip on hover', () => {
it('should toggle the visibility of tooltip on hover', async () => {
const onVisibleChange = vi.fn();

const { getByText } = render(
Expand All @@ -23,11 +23,11 @@ it('should toggle the visibility of tooltip on hover', () => {
expect(tooltip).toHaveAttribute('popover', 'manual');

fireEvent.mouseEnter(trigger);
expect(tooltip).toBeVisible();
await waitFor(() => expect(tooltip).toBeVisible());
expect(onVisibleChange).toBeCalledWith(true);

fireEvent.mouseLeave(trigger);
expect(tooltip).not.toBeVisible();
await waitFor(() => expect(tooltip).not.toBeVisible());
expect(onVisibleChange).toBeCalledWith(false);
});

Expand Down Expand Up @@ -135,8 +135,6 @@ it.each(['description', 'label', 'none'] as const)(
);

it('should work with reference prop', async () => {
vi.useFakeTimers();

const TestComp = () => {
const [reference, setReference] = React.useState<HTMLElement | null>(null);
return (
Expand All @@ -155,18 +153,14 @@ it('should work with reference prop', async () => {
expect(tooltip).not.toBeVisible();

fireEvent.mouseEnter(trigger);
expect(tooltip).toBeVisible();
await waitFor(() => void expect(tooltip).toBeVisible());

fireEvent.mouseLeave(trigger);
expect(tooltip).not.toBeVisible();
await waitFor(() => void expect(tooltip).not.toBeVisible());

fireEvent.focus(trigger);
act(() => void vi.advanceTimersByTime(50));
expect(tooltip).toBeVisible();
await waitFor(() => void expect(tooltip).toBeVisible());

fireEvent.blur(trigger);
act(() => void vi.advanceTimersByTime(250));
expect(tooltip).not.toBeVisible();

vi.useRealTimers();
await waitFor(() => void expect(tooltip).not.toBeVisible());
});
2 changes: 1 addition & 1 deletion packages/itwinui-react/src/core/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const useTooltip = (options: TooltipOptions = {}) => {

const interactions = useInteractions([
useHover(floating.context, {
delay: delay ?? { open: 50, close: 250 },
delay: delay !== 0 ? delay : { open: 50, close: 250 }, // If FloatingDelayGroup exists, use its delay
handleClose: safePolygon({ buffer: -Infinity }),
move: false,
}),
Expand Down

0 comments on commit aaa0e3e

Please sign in to comment.