-
Notifications
You must be signed in to change notification settings - Fork 13.8k
regression: tooltips not reappearing on subsequent hovers #41428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dionisio-bot
merged 4 commits into
release-8.7.0
from
regression/tooltip-not-reappearing-on-rehover
Jul 22, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
203 changes: 203 additions & 0 deletions
203
packages/ui-client/src/providers/TooltipProvider.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| /* eslint-disable testing-library/prefer-user-event */ | ||
| import { act, fireEvent, render, screen } from '@testing-library/react'; | ||
|
|
||
| import TooltipProvider from './TooltipProvider'; | ||
|
|
||
| beforeEach(() => { | ||
| jest.useFakeTimers(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.useRealTimers(); | ||
| }); | ||
|
|
||
| const setup = () => { | ||
| render( | ||
| <TooltipProvider> | ||
| <button type='button' title='Hello'> | ||
| anchor | ||
| </button> | ||
| </TooltipProvider>, | ||
| ); | ||
|
|
||
| return { | ||
| anchor: screen.getByRole('button', { name: 'anchor' }), | ||
| }; | ||
| }; | ||
|
|
||
| const waitForTooltipDebounce = () => { | ||
| act(() => { | ||
| jest.advanceTimersByTime(300); | ||
| }); | ||
| }; | ||
|
|
||
| it('should show the tooltip on hover and stash the title attribute', () => { | ||
| const { anchor } = setup(); | ||
|
|
||
| fireEvent.mouseOver(anchor); | ||
| waitForTooltipDebounce(); | ||
|
|
||
| expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('Hello'); | ||
| expect(anchor).toHaveAttribute('title', ''); | ||
| expect(anchor).toHaveAttribute('data-title', 'Hello'); | ||
| }); | ||
|
|
||
| it('should restore the title attribute on unhover without depending on timers', () => { | ||
| const { anchor } = setup(); | ||
|
|
||
| fireEvent.mouseOver(anchor); | ||
| waitForTooltipDebounce(); | ||
| fireEvent.mouseLeave(anchor); | ||
|
|
||
| // the title must be restored synchronously on unmount, before any timer runs; otherwise a still-attached | ||
| // MutationObserver can blank it again, permanently suppressing the tooltip for this element | ||
| expect(screen.queryByRole('tooltip', { hidden: true })).not.toBeInTheDocument(); | ||
| expect(anchor).toHaveAttribute('title', 'Hello'); | ||
| expect(anchor).not.toHaveAttribute('data-title'); | ||
| }); | ||
|
|
||
| it('should show the tooltip again after a full close and reopen cycle', () => { | ||
| const { anchor } = setup(); | ||
|
|
||
| fireEvent.mouseOver(anchor); | ||
| waitForTooltipDebounce(); | ||
| fireEvent.mouseLeave(anchor); | ||
| act(() => { | ||
| jest.runOnlyPendingTimers(); | ||
| }); | ||
| expect(screen.queryByRole('tooltip', { hidden: true })).not.toBeInTheDocument(); | ||
|
|
||
| fireEvent.mouseOver(anchor); | ||
| waitForTooltipDebounce(); | ||
|
|
||
| expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('Hello'); | ||
| }); | ||
|
|
||
| it('should update the tooltip and re-stash the title when it changes while open', async () => { | ||
| const { anchor } = setup(); | ||
|
|
||
| fireEvent.mouseOver(anchor); | ||
| waitForTooltipDebounce(); | ||
|
|
||
| // the MutationObserver callback runs as a microtask, so the update must be flushed asynchronously | ||
| await act(async () => { | ||
| anchor.setAttribute('title', 'World'); | ||
| }); | ||
|
|
||
| expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('World'); | ||
| expect(anchor).toHaveAttribute('title', ''); | ||
| expect(anchor).toHaveAttribute('data-title', 'World'); | ||
| }); | ||
|
|
||
| describe('click-dismiss while still hovering', () => { | ||
| it('should keep the title stashed after a click-dismiss while the cursor is still on the anchor', () => { | ||
| const { anchor } = setup(); | ||
|
|
||
| fireEvent.mouseOver(anchor); | ||
| waitForTooltipDebounce(); | ||
| expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('Hello'); | ||
|
|
||
| fireEvent.click(anchor); | ||
|
|
||
| expect(screen.queryByRole('tooltip', { hidden: true })).not.toBeInTheDocument(); | ||
| expect(anchor).toHaveAttribute('title', ''); | ||
| expect(anchor).toHaveAttribute('data-title', 'Hello'); | ||
| }); | ||
|
|
||
| it('should restore the title when the cursor leaves after a click-dismiss', () => { | ||
| const { anchor } = setup(); | ||
|
|
||
| fireEvent.mouseOver(anchor); | ||
| waitForTooltipDebounce(); | ||
| fireEvent.click(anchor); | ||
|
|
||
| fireEvent.mouseLeave(anchor); | ||
|
|
||
| expect(anchor).toHaveAttribute('title', 'Hello'); | ||
| expect(anchor).not.toHaveAttribute('data-title'); | ||
| }); | ||
|
|
||
| it('should show the tooltip again after a click-dismiss and mouseleave cycle', () => { | ||
| const { anchor } = setup(); | ||
|
|
||
| fireEvent.mouseOver(anchor); | ||
| waitForTooltipDebounce(); | ||
| fireEvent.click(anchor); | ||
| fireEvent.mouseLeave(anchor); | ||
| act(() => { | ||
| jest.runOnlyPendingTimers(); | ||
| }); | ||
|
|
||
| fireEvent.mouseOver(anchor); | ||
| waitForTooltipDebounce(); | ||
|
|
||
| expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('Hello'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('with a `data-tooltip`-only anchor', () => { | ||
| const setupDataTooltip = () => { | ||
| render( | ||
| <TooltipProvider> | ||
| <button type='button' data-tooltip='Hello'> | ||
| anchor | ||
| </button> | ||
| </TooltipProvider>, | ||
| ); | ||
|
|
||
| return { | ||
| anchor: screen.getByRole('button', { name: 'anchor' }), | ||
| }; | ||
| }; | ||
|
|
||
| it('should show the tooltip without ever adding a title attribute', () => { | ||
| const { anchor } = setupDataTooltip(); | ||
|
|
||
| fireEvent.mouseOver(anchor); | ||
| waitForTooltipDebounce(); | ||
|
|
||
| expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('Hello'); | ||
| expect(anchor).not.toHaveAttribute('title'); | ||
| expect(anchor).not.toHaveAttribute('data-title'); | ||
|
|
||
| fireEvent.mouseLeave(anchor); | ||
|
|
||
| // the anchor must not gain a native title on close; that would leak the tooltip text to the browser's tooltip | ||
| expect(screen.queryByRole('tooltip', { hidden: true })).not.toBeInTheDocument(); | ||
| expect(anchor).not.toHaveAttribute('title'); | ||
| expect(anchor).not.toHaveAttribute('data-title'); | ||
| }); | ||
|
|
||
| it('should update the tooltip when `data-tooltip` changes while open', async () => { | ||
| const { anchor } = setupDataTooltip(); | ||
|
|
||
| fireEvent.mouseOver(anchor); | ||
| waitForTooltipDebounce(); | ||
|
|
||
| // the MutationObserver callback runs as a microtask, so the update must be flushed asynchronously | ||
| await act(async () => { | ||
| anchor.setAttribute('data-tooltip', 'World'); | ||
| }); | ||
|
|
||
| expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('World'); | ||
| expect(anchor).not.toHaveAttribute('title'); | ||
| }); | ||
|
|
||
| it('should show the tooltip again after a click-dismiss and mouseleave cycle', () => { | ||
| const { anchor } = setupDataTooltip(); | ||
|
|
||
| fireEvent.mouseOver(anchor); | ||
| waitForTooltipDebounce(); | ||
| fireEvent.click(anchor); | ||
| fireEvent.mouseLeave(anchor); | ||
| act(() => { | ||
| jest.runOnlyPendingTimers(); | ||
| }); | ||
|
|
||
| fireEvent.mouseOver(anchor); | ||
| waitForTooltipDebounce(); | ||
|
|
||
| expect(screen.getByRole('tooltip', { hidden: true })).toHaveTextContent('Hello'); | ||
| expect(anchor).not.toHaveAttribute('title'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.