-
Notifications
You must be signed in to change notification settings - Fork 646
fix(TooltipV2): delay tooltip opening time by 50ms #5350
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
francinelucca
merged 11 commits into
main
from
francinelucca/4432-bug-tooltip-on-iconbutton-should-not-show-up-instantly
Dec 13, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d4e1eb7
fix(TooltipV2): delay tooltip opening time by ms
francinelucca 3fcdbdd
Create five-mayflies-flash.md
francinelucca f62bf38
Merge branch 'main' of github.com:primer/react into francinelucca/443…
francinelucca 4d4cbcc
fix(Overlay): use fire event for click in test and set popover to fal…
francinelucca a5bbca5
fix(Overlay): remove redundant await
francinelucca bb7ebcb
Merge branch 'main' into francinelucca/4432-bug-tooltip-on-iconbutton…
francinelucca 2073d41
Merge branch 'main' into francinelucca/4432-bug-tooltip-on-iconbutton…
francinelucca 7bc59c4
fix(TooltipV2): use safeTimeout
francinelucca 5f5738d
Merge branch 'main' into francinelucca/4432-bug-tooltip-on-iconbutton…
francinelucca 15ce545
Merge branch 'main' of github.com:primer/react into francinelucca/443…
francinelucca bed7c74
fix(TooltipV2): change type of timeoutRef
francinelucca 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@primer/react": patch | ||
| --- | ||
|
|
||
| fix(TooltipV2): delay tooltip opening time by ms |
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 |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import classes from './Tooltip.module.css' | |
| import {useFeatureFlag} from '../FeatureFlags' | ||
| import {KeybindingHint, type KeybindingHintProps} from '../KeybindingHint' | ||
| import VisuallyHidden from '../_VisuallyHidden' | ||
| import useSafeTimeout from '../hooks/useSafeTimeout' | ||
|
|
||
| const CSS_MODULE_FEATURE_FLAG = 'primer_react_css_modules_team' | ||
|
|
||
|
|
@@ -213,6 +214,10 @@ export const Tooltip = React.forwardRef( | |
|
|
||
| const [isPopoverOpen, setIsPopoverOpen] = useState(false) | ||
|
|
||
| const timeoutRef = React.useRef<number | null>(null) | ||
|
|
||
| const {safeSetTimeout, safeClearTimeout} = useSafeTimeout() | ||
|
|
||
| const openTooltip = () => { | ||
| try { | ||
| if ( | ||
|
|
@@ -265,6 +270,8 @@ export const Tooltip = React.forwardRef( | |
| ) { | ||
| tooltipElRef.current.hidePopover() | ||
| setIsPopoverOpen(false) | ||
| } else { | ||
| setIsPopoverOpen(false) | ||
|
Comment on lines
+273
to
+274
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixes bug where overlay would stay "stuck" and not able to close via keyboard due to popOver state being open but it not actually being in the DOM |
||
| } | ||
| } catch (error) { | ||
| // older browsers don't support the :popover-open selector and will throw, even though we use a polyfill | ||
|
|
@@ -362,10 +369,18 @@ export const Tooltip = React.forwardRef( | |
| child.props.onFocus?.(event) | ||
| }, | ||
| onMouseEnter: (event: React.MouseEvent) => { | ||
| openTooltip() | ||
| child.props.onMouseEnter?.(event) | ||
| // show tooltip after mosue has been hovering for at least 50ms | ||
| // (prevent showing tooltip when mouse is just passing through) | ||
| timeoutRef.current = safeSetTimeout(() => { | ||
| openTooltip() | ||
| child.props.onMouseEnter?.(event) | ||
| }, 50) | ||
| }, | ||
| onMouseLeave: (event: React.MouseEvent) => { | ||
| if (timeoutRef.current) { | ||
| safeClearTimeout(timeoutRef.current) | ||
| timeoutRef.current = null | ||
| } | ||
| closeTooltip() | ||
| child.props.onMouseLeave?.(event) | ||
| }, | ||
|
|
||
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.
I tried for minute to get this to work with user.click, I replicated this test manually in storybook and it works as expected. I noticed userEvent was triggering different events than manual testing did 🤷🏽♀️