-
Notifications
You must be signed in to change notification settings - Fork 203
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
Display a popover when hovering over highlighted mentions #6820
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6820 +/- ##
==========================================
- Coverage 99.45% 99.42% -0.03%
==========================================
Files 271 272 +1
Lines 10409 10451 +42
Branches 2488 2503 +15
==========================================
+ Hits 10352 10391 +39
- Misses 57 60 +3 ☔ View full report in Codecov by Sentry. |
bc353c1
to
2f22ac3
Compare
21c7577
to
2b48087
Compare
2f22ac3
to
c989091
Compare
2b48087
to
2616ac2
Compare
The hover card currently appears immediately when a user's name is hovered, causing a flash if the cursor just happens to be passing over the mention. On GitHub, Reddit etc. to avoid this there is typically a short delay (100ms? I haven't measured it exactly) after the cursor enters the mention before the card is shown. |
Yeah, good idea. |
116dfb1
to
79e9832
Compare
if (content === null) { | ||
setContent(); | ||
} else { | ||
popoverContentTimeout.current = setTimeout_(setContent, 400); |
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.
Popovers appear after hovering for 400ms. I compared the time it takes in GitHub, and this is the value I came up "by eye", because I wasn't able to find a way to properly measure it.
I started with 100, then I realized it was showing much faster than in GitHub, so I tried with 200, then 400. At that point it felt close enough, but it took me a couple attempts 😅 |
ed351df
to
306ee40
Compare
<div | ||
className={classes} | ||
data-testid="markdown-text" | ||
ref={content} | ||
dangerouslySetInnerHTML={{ __html: html }} | ||
style={style} | ||
// React types do not define `onMouseEnterCapture`, but preact does | ||
// eslint-disable-next-line react/no-unknown-property |
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.
Disabling react/no-unknown-property
here is needed because it evaluates props based on react types, not preact ones, where the Capture
variants of event handlers are not defined.
We discussed in slack the possibility of completely disabling react/no-unknown-property
, since TypeScript covers the same, more accurately, but I will do that on a PR of its own.
5d44c1a
to
1bd3f9c
Compare
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.
This contents are very much temporary, because matching the designs requires some extra API changes.
I'm defining a separate component, so that's easier to extend it and its test as soon as we have the missing pieces.
Codecov is complaining about two lines that are marked with |
I investigated the default argument coverage issue and filed istanbuljs/istanbuljs#812 upstream. I found a workaround which I documented here: istanbuljs/istanbuljs#812 (comment) |
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.
This looks good. I provided a workaround for the code coverage issue and some minor suggestions. One behavioral change I think we should make in future is that the popover should not disappear if the mouse leaves the mention element and moves on to the popover. This will enable adding links etc. in the popover, but also I think hiding the popover if the mouse moves into it is simply a little surprising.
); | ||
const [popoverContent, doSetPopoverContent] = useState<PopoverContent>(null); | ||
const popoverContentTimeout = useRef<ReturnType<typeof setTimeout> | null>(); | ||
const setPopoverContent = useCallback( |
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.
There is nothing to clear the timer if the component gets unmounted after a hover has started but before the popover has been shown. You could use a layout effect cleanup function to handle this. A completely different approach would be to use an animation on the popover container to cause the delayed appearance (ie. the 400ms delay would become a transition on eg. visibility
).
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'll add the effect cleanup function and check how difficult would be to use a native animation afterwards.
Yeah, I have been thinking about this. I think it should not be super hard to do, but requires some testing. If at some point we add a gap between the anchor element and the popover, we may have to also set a delay to the popover hiding. I'll create an issue with some notes on the most important considerations. EDIT: #6821 |
0a0602c
to
98a0390
Compare
98a0390
to
bcbe3ae
Compare
Depends on #6818
Closes #6804
Display a popover with basic user information when hovering over a highlighted valid mention, whether it is a link or not.
Additionally, display a popover indicating a user does not exist when hovering over an invalid mention.
Popovers appear with a 400ms delay, to avoid a lot of flickering when hovering over annotations.
popover-with-delay-2025-02-12_12.35.53.mp4