Skip to content
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

fix(tooltip): tooltip stays open on fast movement #4482

Open
wants to merge 4 commits into
base: canary
Choose a base branch
from

Conversation

Connorelsea
Copy link

@Connorelsea Connorelsea commented Jan 2, 2025

Closes #4301

📝 Description

This PR fixes an issue where tooltips when hovered in quick succession would sometimes remain open in NextUI. It updates AnimatePresence and motion key handling to comply with motion's typical usage patterns.

⛳️ Current behavior (updates)

When moving a cursor quickly across a screen with many tooltips, some tooltips would stay open after mouse has left. This can be easily replicated by making a list of tooltips and moving the cursor up and down them at medium-quick speed, especially when closeDelay and openDelay are set to zero to increase the chance that interruptions of the close animation will occur.

🚀 New behavior

Tooltip no longer stays open on fast mouse movements across a list of tooltips. This ensures AnimatePresence is not prematurely unrendered on tooltip close by ensuring AnimatePresence is always rendered when disableAnimation is false, and not unrendered when isOpen is false. Previously animate presence was being unrendered on close due to the conditional combining isOpen and disableAnimation checks. This also adds the proper keys that allow framer-motion to properly track these animations. Removing the keys causes the regression to return.

💣 Is this a breaking change (Yes/No):

No breaking changes, small internal fix to tooltip with no effect on current usage patterns.

📝 Additional Information

I tried to think of a way to test this programatically, but I could not think of anything good. I added a storybook where I was able to test manually and replicate this issue locally on the canary branch. You can replicate by removing the keys and moving your cursor quickly up and down the list. Adding the keys back, alongside the change in AnimatePresence rendering, seemingly eliminates this behavior.

If someone can think of a better way to write a test for this, or wants to remove the storybook (or present it differently) as it was mostly used for testing this issue, let me know! I am available to make changes to this PR.

Replicated on public docs:

Screen.Recording.2024-12-29.at.2.59.07.PM.mov

Replicated on the storybook I added (pre-fix)

telegram-cloud-photo-size-1-5168126915008114304-y

Summary by CodeRabbit

  • New Features

    • Enhanced tooltip rendering with improved animation handling.
    • Added a new story template demonstrating multiple tooltips with immediate open/close behavior.
  • Improvements

    • Simplified tooltip content rendering logic.
    • Improved element identification during tooltip transitions.
    • Fixed an issue where tooltips remained open during fast movements.

Copy link

changeset-bot bot commented Jan 2, 2025

🦋 Changeset detected

Latest commit: fc1b18a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@nextui-org/tooltip Patch
@nextui-org/slider Patch
@nextui-org/snippet Patch
@nextui-org/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jan 2, 2025

@Connorelsea is attempting to deploy a commit to the NextUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

Walkthrough

The pull request modifies the Tooltip component to improve its rendering and animation logic. The changes focus on enhancing the component's behavior when multiple tooltips are rapidly interacted with. A new key prop is added to the animated content to improve element identification during transitions. The conditional rendering for tooltip content has been simplified, allowing for more precise control over animation and visibility. Additionally, a patch update is introduced to the @nextui-org/tooltip package to ensure tooltips close appropriately during rapid cursor movements.

Changes

File Change Summary
packages/components/tooltip/src/tooltip.tsx - Added key prop to animated content derived from id
- Simplified conditional rendering for tooltip content
- Improved handling of disableAnimation and isOpen states
packages/components/tooltip/stories/tooltip.stories.tsx - Added ManyTemplate to demonstrate multiple tooltips
- Created new Many export with immediate open/close behavior
.changeset/two-insects-provide.md - Updated @nextui-org/tooltip package to fix tooltip behavior during fast movements

Assessment against linked issues

Objective Addressed Explanation
Prevent tooltips from staying open too long [#4301]
Handle rapid mouse movement over multiple tooltips [#4301]

Possibly related PRs

Suggested reviewers

  • jrgarciadev

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 709d574 and fc1b18a.

📒 Files selected for processing (1)
  • .changeset/two-insects-provide.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/two-insects-provide.md

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jrgarciadev
Copy link
Member

Hey @Connorelsea thanks, please add a changeset

@wingkwong wingkwong changed the title fix(components): tooltip stays open on fast movement fix(tooltip): tooltip stays open on fast movement Jan 3, 2025
@Connorelsea
Copy link
Author

Hello @jrgarciadev, I added a changeset, tried to follow the linked changeset documentation as I have never used that tool before. If it's incorrect I can fix it.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.changeset/two-insects-provide.md (1)

5-5: Consider enhancing the changeset description.

While the description captures the essence of the change, it would be more helpful for future reference if you could include:

  • The specific motion keys that were added
  • Details about the AnimatePresence rendering changes
  • Any performance implications of these changes
-fix tooltip staying open on fast movement by adding proper motion keys and ensuring AnimatePresence stays rendered, no breaking changes or usage changes required
+fix tooltip staying open on fast movement by:
+- adding unique motion keys to tooltip content for proper animation tracking
+- ensuring AnimatePresence component remains mounted until animations complete
+- improving render performance during rapid tooltip transitions
+
+No breaking changes or usage changes required.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6408d7 and ab7167e.

📒 Files selected for processing (1)
  • .changeset/two-insects-provide.md (1 hunks)
🔇 Additional comments (1)
.changeset/two-insects-provide.md (1)

1-3: LGTM! Version bump is appropriate.

The minor version bump is correctly chosen as this change adds functionality in a backward-compatible manner.

@wingkwong wingkwong modified the milestones: v2.6.11, v2.6.12 Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] - Tooltip stays open more than it should
3 participants