Skip to content

fix: tooltip showing when data-tip or tooltip-content is empty. closes: #3819 #3821

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 1 commit into from
Apr 30, 2025

Conversation

sulimanbenhalim
Copy link
Contributor

Problem

Fixes #3819

When a tooltip has an empty data-tip attribute or empty tooltip-content, it still shows a small artifact on hover. This looks like a UI bug.

Fix

I added CSS rules to hide the tooltip when:

  • data-tip attribute is missing
  • data-tip attribute is empty
  • tooltip-content is empty
  • tooltip-content only has empty children

Now empty tooltips don't show up at all, which is what users would expect.

Testing

I tested this with examples from the issue:

  • Tooltip with empty data-tip=""
  • Tooltip with empty tooltip-content

Before: Empty tooltips showed a strange artifact
After: Empty tooltips stay completely hidden

@saadeghi saadeghi self-assigned this Apr 25, 2025
Copy link
Owner

@saadeghi saadeghi left a comment

Choose a reason for hiding this comment

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

Hey 👋
Thanks for the PR.
Can you apply these changes please?

  • use nesting to avoid duplicate selectors when possible
  • do not use !important

@sulimanbenhalim sulimanbenhalim force-pushed the fix-tooltip-empty-content branch from 6becb28 to a467023 Compare April 25, 2025 15:25
@sulimanbenhalim
Copy link
Contributor Author

sulimanbenhalim commented Apr 25, 2025

Hey @saadeghi I updated the code using nesting as requested

this covers:

  • Elements with no data-tip attribute
  • Elements with empty data-tip=""
  • Elements without tooltip-content div

Note: This does not cover cases with empty tooltip-content divs like <div class="tooltip-content"><div></div></div>.
That's why the initial solution covered all 4 cases

@saadeghi
Copy link
Owner

This does not cover cases with empty tooltip-content divs like <div class="tooltip-content"></div>

That's ok.
Since developers can decide when to render that div.
Also, :empty selector may not work all the time, especially when HTML is being rendered by frameworks and may include spaces inside the div, in that case it won't be counted as :empty

@sulimanbenhalim
Copy link
Contributor Author

That's ok. Since developers can decide when to render that div.

You are right I think I just overthought the solution by focusing too much on special cases.

Also, :empty selector may not work all the time, especially when HTML is being rendered by frameworks and may include spaces inside the div, in that case it won't be counted as :empty

I tested with whitespace in the div and :empty still catches it correctly, so now it is working as intended you can double check, peace!

@saadeghi saadeghi merged commit 2414ca5 into saadeghi:master Apr 30, 2025
1 check passed
@sulimanbenhalim sulimanbenhalim deleted the fix-tooltip-empty-content branch April 30, 2025 17:16
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 shows a part of tip with blank or missing data-tip/tooltip-content
2 participants