Skip to content

Link preview: do not add elements inside headers #592

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 4 commits into from
Jun 3, 2025
Merged

Conversation

humitos
Copy link
Member

@humitos humitos commented Jun 2, 2025

Closes #584

@humitos humitos requested a review from a team as a code owner June 2, 2025 14:49
@humitos humitos requested a review from agjohnson June 2, 2025 14:49
There is no need to add the tooltip next to the anchor element where the tooltip
is going to be displayed. The position is pre-calculated and it does not
interfere where in the DOM is added.

To simplify, I'm adding the tooltips always before closing the body of the page.
Copy link
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

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

I'm mostly confident what I pointed out is not a problem but it's hard to say definitively. If we see in testing that any tooltips are not lining up with the link trigger elements, that would confirm my suspicion.

@@ -189,7 +189,7 @@ function setupTooltip(el, doctoolname, doctoolversion, selector) {
);
newTooltip.setAttribute(TOOLTIP_DATA_HREF, anchorElement.href);
newTooltip.classList.add("tooltip");
anchorElement.insertAdjacentElement("afterend", newTooltip);
document.body.insertAdjacentElement("beforeend", newTooltip);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering what effect this might have. I assumed looking at this code that the element was inserted adjacently for positioning purposes. For example, if the tooltip is positioned relatively, measuring from the document body would be different than the measurement from a sibling element to the tooltip trigger element.

This might be noticeable if the link was inside an element that had a large margin-left for example, as the document body would not have this.

But as far as I can tell this doesn't look like it should be the case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Positioning or similar shouldn't be an issue because it's based on the original anchor element: https://github.com/readthedocs/addons/blob/humitos%2Flp-headers/src/linkpreviews.js#L125-L155

As far as I can tell, all the tooltip previews I've tested are well positioned 👍🏼

@humitos humitos merged commit d3c7cce into main Jun 3, 2025
4 checks passed
@humitos humitos deleted the humitos/lp-headers branch June 3, 2025 09:10
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.

Link preview of a link inside an h2 incorrectly inherits h2 styling for preview content?
2 participants