Skip to content

fix: defer resolution of tooltip target - #5674

Merged
bwajtr merged 3 commits into
mainfrom
5423-tooltip-rendered-at-wrong-location
Mar 17, 2023
Merged

bwajtr merged 3 commits into
mainfrom
5423-tooltip-rendered-at-wrong-location

Conversation

@bwajtr

@bwajtr bwajtr commented Mar 15, 2023 •

Copy link
Copy Markdown
Contributor

Description

The tooltip uses it's for attribute to control the target element to which the tooltip is attached. The for attribute contains the id of the target element. There is a _forChanged observer in the tooltip, which resolves a new target element whenever for changes. As long as the id is unique on the page, this works as expected.

However, there are situations when there are duplicate ids on the page, although it's not the author's intent. When you render a list of items using lit .map() function and you then reorder the source list in any way, the lit reacts by rerendeing the content. However, the already created elements on the page are not thrown away or their content cleared before the rerender - elements are reused, and only the diffing parts are rewritten one by one. So it's entirely possible that during the rendering process there are two exactly same items (also with same id) on the page. That is a problem for a tooltip, which can then resolve incorrect target element. You have to wait until the rerendering finishes to be sure that all changes have been applied and all ids are unique again.

This also happens when vaadin-grid is rerendering the content after the items have been sorted differently.
The following image shows a state where we are in the middle of such "rerender after sort change":
https://user-images.githubusercontent.com/1890879/222460683-275c6f9a-ac3e-4426-a048-bfd7635a1bc5.png

I can imagine that any custom lit directive which handles list rendering will probably show the same behavior.

This PR solves this problem by deferring the resolution of the target element of the tooltip only after the current rendering is done and ids of all involved elements become stable and final again.

Fixes #5423

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/contributing/overview
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Comment thread integration/tests/grid-tooltip.test.js Resolved
@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@bwajtr
bwajtr requested a review from tomivirkki March 17, 2023 10:03
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 24.1.0.alpha1 and is also targeting the upcoming stable 24.1.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tooltip rendered at wrong location

3 participants