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

[GEN-2079]: enhance tooltip positioning logic with useRef for better accuracy #2041

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

BenElferink
Copy link
Contributor

This pull request includes several enhancements to the Tooltip component in the frontend/webapp/reuseable-components/tooltip/index.tsx file. The changes focus on improving the tooltip's positioning logic and code maintainability.

Key changes include:

Enhancements to Tooltip Positioning:

  • Added useRef and forwardRef to manage the tooltip's positioning more accurately using the actual dimensions of the tooltip element. [1] [2] [3]
  • Modified the handleMouseEvent function to use the tooltip's dimensions for positioning instead of relying on text length.

Code Simplification:

  • Consolidated imports and removed redundant ones to clean up the code.

Copy link

if (top >= innerHeight / 2) top += -40;
if (left >= innerWidth / 2) left += -(textLen * 8);
if (top >= innerHeight / 2) top += -(popupRef.current?.clientHeight || 40);
if (left >= innerWidth / 2) left += -(popupRef.current?.clientWidth || Math.min((text?.length || 0) * 7.5, 300));
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems a little bit risky, did you try this with long text?

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.

2 participants