Skip to content
This repository has been archived by the owner on Nov 9, 2024. It is now read-only.

fix contains algorithm for shadow dom #915

Merged
merged 2 commits into from
Mar 3, 2021
Merged

Conversation

zhaoyao91
Copy link
Contributor

For such a structure where content is a shadow dom:

popperContainer
  contentElement(shadowDom)
    innerElement
    innerElement
    ...

If we click on innerElement, the popperContainer.contains(innerElement) will return false since it is inside a shadow root. But in tippy's logic, we need to treat popperContainer containing innerElement as true.

So here comes actualContains function which check through the shadow dom to maintain the correct logic.

Without this fix, interactive option will not work for dom structure above, see:

Kapture 2021-03-02 at 20 42 31

Comment on lines 305 to 315
function actualContains(parent: Element, child: Element): boolean {
let target = child;
while(target) {
if (parent.contains(target)) {
return true;
}
target = (child.getRootNode() as any)?.host;
}
return false;
}

Copy link
Owner

Choose a reason for hiding this comment

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

Can you move this into dom-utils

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@atomiks
Copy link
Owner

atomiks commented Mar 3, 2021

Linting/Type checking is failing as tsd needs to be updated, I'll do that after merge, thank you

@atomiks atomiks merged commit cf38a3d into atomiks:master Mar 3, 2021
@zhaoyao91 zhaoyao91 deleted the patch-4 branch May 12, 2021 10:09
@twilson90
Copy link

I checked the latest release, this fix doesn't appear to be in there.
interactive: true still doesn't work for elements within a shadow dom.

@zhaoyao91
Copy link
Contributor Author

I checked the latest release, this fix doesn't appear to be in there.
interactive: true still doesn't work for elements within a shadow dom.

@hedgehog90 yes, tippy does not release yet since then.

@mvromer
Copy link

mvromer commented Sep 20, 2021

I'd be very much interested in a new release of tippy that includes this fix as well. I'm currently working on adding tooltip and context menu support to elements that are rendered in a shadow DOM. Tippy has been awesome for this, but right now I'm not able to get click events on context menu items without a few additional workarounds.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants