Repository navigation
fix: Escape, closing fade and CSS variable edge cases #1294
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
Open
gogakoreli
wants to merge
7
commits into
ReactTooltip:master
Choose a base branch
from
gogakoreli:fix/escape-and-removal-edges
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7f5bfc2
fix: cancel a pending show on Escape
gogakoreli 5181b91
fix: forget the pointer and a pending hide once a clickable tooltip i…
gogakoreli 1c65258
fix: wait out the closing transition before removing a closed tooltip
gogakoreli 2641153
fix: end the closing fade on the tooltip's own transition only
gogakoreli faa3bb1
fix: read the closing transition length on the tooltip
gogakoreli 50a1643
fix: let a :root rule override the default CSS variables
gogakoreli e550523
fix: time the fallback removal by a calc() closing delay too
gogakoreli 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
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
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
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
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
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,91 @@ | ||
| import React from 'react' | ||
| import { render, screen, waitFor } from '@testing-library/react' | ||
| import '@testing-library/jest-dom' | ||
| import { TooltipController } from '../components/TooltipController' | ||
| import { | ||
| advanceTimers, | ||
| flushPendingTimers, | ||
| hoverAnchor, | ||
| unhoverAnchor, | ||
| waitForTooltip, | ||
| } from './test-utils' | ||
|
|
||
| jest.mock('@floating-ui/dom', () => { | ||
| const originalModule = jest.requireActual('@floating-ui/dom') | ||
| return { | ||
| ...originalModule, | ||
| autoUpdate: jest.fn(() => jest.fn()), | ||
| } | ||
| }) | ||
|
|
||
| const TOOLTIP_ID = 'closing-transition-test' | ||
| const getTooltip = () => document.getElementById(TOOLTIP_ID) | ||
|
|
||
| const showThenClose = async (tooltipProps) => { | ||
| render( | ||
| <> | ||
| <span data-tooltip-id={TOOLTIP_ID}>Hover Me</span> | ||
| <TooltipController id={TOOLTIP_ID} content="Closing Transition Test" {...tooltipProps} /> | ||
| </>, | ||
| ) | ||
|
|
||
| const anchor = screen.getByText('Hover Me') | ||
| hoverAnchor(anchor, 100) | ||
| await waitForTooltip(TOOLTIP_ID) | ||
| await waitFor(() => { | ||
| expect(getTooltip()).toHaveClass('react-tooltip__show') | ||
| }) | ||
|
|
||
| unhoverAnchor(anchor, 20) | ||
| expect(getTooltip()).toHaveClass('react-tooltip__closing') | ||
| } | ||
|
|
||
| describe('tooltip closing transition', () => { | ||
| beforeEach(() => { | ||
| jest.useFakeTimers() | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| flushPendingTimers() | ||
| jest.useRealTimers() | ||
| }) | ||
|
|
||
| test('keeps a closing tooltip for its closing transition when it is longer than the show transition', async () => { | ||
| await showThenClose({ | ||
| style: { '--rt-transition-show-delay': '0.15s', '--rt-transition-closing-delay': '0.6s' }, | ||
| }) | ||
|
|
||
| // half way through the 0.6s closing transition | ||
| advanceTimers(300) | ||
| expect(getTooltip()).toBeInTheDocument() | ||
|
|
||
| // removed after it, even if no `transitionend` fires | ||
| advanceTimers(400) | ||
| expect(getTooltip()).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('keeps a closing tooltip for its closing transition when the length is set on the tooltip', async () => { | ||
| // nothing on body: the length is read where the transition runs | ||
| await showThenClose({ style: { '--rt-transition-closing-delay': '0.6s' } }) | ||
|
|
||
| advanceTimers(300) | ||
| expect(getTooltip()).toBeInTheDocument() | ||
|
|
||
| advanceTimers(400) | ||
| expect(getTooltip()).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('keeps a closing tooltip for its closing transition when the length is a calc() expression', async () => { | ||
| // a custom property keeps `calc()` as written. jsdom does not apply the closing class's | ||
| // stylesheet, so the resolved length of the closing transition is set directly | ||
| await showThenClose({ | ||
| style: { '--rt-transition-closing-delay': 'calc(0.3s + 0.3s)', transitionDuration: '0.6s' }, | ||
| }) | ||
|
|
||
| advanceTimers(300) | ||
| expect(getTooltip()).toBeInTheDocument() | ||
|
|
||
| advanceTimers(400) | ||
| expect(getTooltip()).not.toBeInTheDocument() | ||
| }) | ||
| }) |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Select the duration for the opacity transition.
With
--rt-transition-closing-delay: calc(0.3s + 0.3s)and inlinetransition: transform 0.1s, opacity var(--rt-transition-closing-delay), this fallback selects0.1s. The timer removes the tooltip after approximately 125ms and callsafterHidebefore the 600ms fade finishes.CSS matches durations to transition properties by list position. The first duration need not describe opacity. (w3.org)
Match the resolved duration to
opacity, includingalland repeated-list handling. Add this multiple-transition case to the regression test.