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

Feature: Use in webcomponent #536

Open
peter-mogensen opened this issue Dec 20, 2020 · 12 comments
Open

Feature: Use in webcomponent #536

peter-mogensen opened this issue Dec 20, 2020 · 12 comments
Labels

Comments

@peter-mogensen
Copy link

What problem does this feature solve?

I tried use create a small webcomponent which panzoom'ed an SVG map within a smaller "viewport". (based on lit-element)

The Panzoom() function returns an error, failing on the test that the panzoom element is not attached to the document - which I suppose is because of the intervening shadow DOM root.

@timmywil timmywil added the needs info This issue needs more info, probably a test case, to continue. It will be reopened if valid. label Dec 21, 2020
@timmywil
Copy link
Owner

Thanks for opening an issue. If you could put together a small example from codepen.io or jsbin.com, that would be very helpful. Don't worry that I'm closing for now. This can still be put into feature pipeline if valid.

@peter-mogensen
Copy link
Author

peter-mogensen commented Dec 23, 2020

I think it's most simply stated that:
If elem is beneath a shadowRoot node in the DOM, then
elem.ownerDocument.documentElement.contains(elem.parentNode);
returns false, and PanZoom refuse to work with it due the the test in isAttached()

@timmywil timmywil removed the needs info This issue needs more info, probably a test case, to continue. It will be reopened if valid. label Sep 17, 2021
@Flurb
Copy link

Flurb commented Dec 5, 2021

Hi @timmywil ,
I was wondering why this issue is closed.
It still cannot be used with shadow ROM right?

@timmywil
Copy link
Owner

timmywil commented Dec 6, 2021

Yes, thanks. I don't know why I didn't reopen. It should be easy enough to fix...I think.

@timmywil timmywil reopened this Dec 6, 2021
@Flurb
Copy link

Flurb commented Dec 6, 2021

Yes, thanks. I don't know why I didn't reopen. It should be easy enough to fix...I think.

Great! Thanks @timmywil !

@Flurb
Copy link

Flurb commented Dec 7, 2021

Just a small question:
Why is there a hard check for doc.nodeType === 9?
The type of Node can also be an Element right?

@timmywil
Copy link
Owner

timmywil commented Dec 7, 2021

The element can be, but it's attached to a document, which has a nodeType of 9. In the case of shadow DOM, we just need to allow that the owner document can be retrieved from the host property of a document fragment.

@yonisabdillahi
Copy link

yonisabdillahi commented Mar 16, 2022

Hi @timmywil,

Great library, I am trying to use the library with Lit Element. Any update on whether shadow dom will be supported. Running into the exact same issue as @Flurb was.

It's a matter of determining if the element being passed in is within a shadow dom.

const isInShadowDom = node.getRootNode() instanceof ShadowRoot

@a-r-w
Copy link

a-r-w commented Mar 19, 2022

In the meantime there's a possible workaround if you're ok using web components without the shadow dom. For Lit, that's done with:

createRenderRoot() {
return this;
}

See https://lit.dev/docs/components/shadow-dom/#renderroot

Note that you'll have to live without such nice features as scoped css.

@a-r-w
Copy link

a-r-w commented Mar 20, 2022

@timmywil here's a simple case in jsfiddle that triggers the "Panzoom should be called on elements that have been attached to the DOM" error: https://jsfiddle.net/a_r_w/a2m46sLf/53/. It also demonstrates the workaround from the comment above.

@vtron
Copy link

vtron commented May 11, 2022

Any updates on this/can this PR be integrated? This is a really awesome lib but as a user of LitElement I am completely blocked until this update is added.

@breakthestatic
Copy link
Contributor

Hey @timmywil, will you be able to take a look at my PR (#618)?

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

No branches or pull requests

7 participants