-
Notifications
You must be signed in to change notification settings - Fork 148
fix: 悬停始终弹出描述tooltip,趋势页新增tooltip #170
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
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
64f9c78
fix: always show hover tooltip for descriptions, add tooltip to trend…
AmintaCCCP a1bacb8
fix: add keyboard/touch accessibility to description tooltips
AmintaCCCP 24d5375
fix: use portal-based tooltip to avoid overflow clipping
AmintaCCCP 6d9ad1f
fix: hover-intent tooltip, useLayoutEffect, rAF throttling
AmintaCCCP 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,78 @@ | ||
| import React, { useEffect, useRef, useCallback } from 'react'; | ||
| import { createPortal } from 'react-dom'; | ||
|
|
||
| interface FloatingTooltipProps { | ||
| content: React.ReactNode; | ||
| visible: boolean; | ||
| triggerRef: React.RefObject<HTMLElement | null>; | ||
| onMouseLeave: () => void; | ||
| } | ||
|
|
||
| export const FloatingTooltip: React.FC<FloatingTooltipProps> = ({ | ||
| content, | ||
| visible, | ||
| triggerRef, | ||
| onMouseLeave, | ||
| }) => { | ||
| const tooltipRef = useRef<HTMLDivElement>(null); | ||
|
|
||
| const updatePosition = useCallback(() => { | ||
| if (!triggerRef.current || !tooltipRef.current || !visible) return; | ||
|
|
||
| const triggerRect = triggerRef.current.getBoundingClientRect(); | ||
| const tooltipEl = tooltipRef.current; | ||
|
|
||
| // Reset height to get natural measurement | ||
| tooltipEl.style.maxHeight = '280px'; | ||
| const tooltipHeight = tooltipEl.offsetHeight; | ||
| const tooltipWidth = triggerRect.width; | ||
|
|
||
| // Position above the trigger | ||
| const top = triggerRect.top - tooltipHeight - 8; | ||
| const left = triggerRect.left; | ||
|
|
||
| // If tooltip would go above viewport, flip it below | ||
| if (top < 8) { | ||
| tooltipEl.style.top = `${triggerRect.bottom + 8}px`; | ||
| tooltipEl.style.bottom = 'auto'; | ||
| // Flip arrow direction | ||
| tooltipEl.dataset.flipped = 'true'; | ||
| } else { | ||
| tooltipEl.style.top = `${top}px`; | ||
| tooltipEl.style.bottom = 'auto'; | ||
| tooltipEl.dataset.flipped = 'false'; | ||
| } | ||
|
|
||
| tooltipEl.style.left = `${left}px`; | ||
| tooltipEl.style.width = `${tooltipWidth}px`; | ||
| }, [triggerRef, visible]); | ||
|
|
||
| useEffect(() => { | ||
| if (visible) { | ||
| updatePosition(); | ||
| const handleResize = () => updatePosition(); | ||
| window.addEventListener('resize', handleResize); | ||
| window.addEventListener('scroll', handleResize, true); | ||
| return () => { | ||
| window.removeEventListener('resize', handleResize); | ||
| window.removeEventListener('scroll', handleResize, true); | ||
| }; | ||
| } | ||
| }, [visible, updatePosition]); | ||
|
|
||
| if (!visible) return null; | ||
|
|
||
| return createPortal( | ||
| <div | ||
| ref={tooltipRef} | ||
| onMouseLeave={onMouseLeave} | ||
| className="fixed z-[9999] p-4 bg-white dark:bg-surface-3 text-gray-900 dark:text-text-primary text-[13px] leading-[1.625] rounded-xl shadow-dialog border border-gray-200/80 dark:border-white/[0.04] animate-fade-in max-h-[280px] overflow-y-auto scrollbar-auto" | ||
| style={{ pointerEvents: 'auto' }} | ||
| > | ||
| <div className="whitespace-pre-wrap break-words pr-2"> | ||
| {content} | ||
| </div> | ||
| </div>, | ||
| document.body | ||
| ); | ||
| }; | ||
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.
Tooltip closes before the user can reach it, breaking scrollable long content. The tooltip is rendered 8px above the trigger and visibility is driven entirely by the trigger wrapper's
onMouseLeave(seeSubscriptionRepoCardlines 415/439 andRepositoryCard). When the cursor leaves the trigger to move onto the tooltip,onMouseLeavefires immediately and unmounts it — so a user can never hover the panel to scroll, which the PR test plan ("长文本 tooltip 内可滚动") requires. AddingonMouseEnterhere alone won't fix it because the trigger has already toggledvisibleto false.Recommend a hover-intent pattern: delay the hide, expose
onMouseEnteron the tooltip to cancel the pending hide, and have consumers clear the timer on re-entry.🛠️ Suggested pattern
interface FloatingTooltipProps { content: React.ReactNode; visible: boolean; triggerRef: React.RefObject<HTMLElement | null>; + onMouseEnter?: () => void; onMouseLeave: () => void; }<div ref={tooltipRef} + onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}Consumers should hide on a short timeout (cleared by the tooltip's
onMouseEnter) instead of synchronously on the wrapper'sonMouseLeave.🤖 Prompt for AI Agents