Skip to content

Conversation

jorgecasar
Copy link
Contributor

Solve #8

@jorgecasar jorgecasar force-pushed the shadow-dom-compatibility branch from d1fdc6e to ec8fee1 Compare November 15, 2018 16:21
@@ -13,7 +13,9 @@ function copy(button: HTMLElement) {
}

function copyTarget(button: Element, id: string) {
const content = button.ownerDocument.getElementById(id)
// $FlowFixMe until https://github.com/facebook/flow/pull/7181 is approved
const root = 'getRootNode' in Element.prototype ? button.getRootNode() : button.ownerDocument
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @jorgecasar thanks for the PR!

Should this be getRootNode() or getRootNode({ composed: true })? I can see use cases for both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According with the specifications of Node.getRootNode:

composed: A Boolean that indicates whether the shadow root should be returned (false, the default), or a root node beyond shadow root (true).

it should be false because we want to find the id inside the Shadow Dom where the button is on. If we put composed: true the document will be returned and we were in the same situation as ownerDocument and we can't find the id inside the Shadow Dom of the web components.

Copy link
Contributor

Choose a reason for hiding this comment

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

What if the element to copy is outside of the shadow root though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It couldn't be supported. There are 2 DOMs, global DOM (Document) or shadow DOM. Then the element should be in one of those. Using Shadow DOM is common to be in the same DOM.

Otherwise we have to rethink the component to provide the element it self to be copied.

@jorgecasar jorgecasar force-pushed the shadow-dom-compatibility branch from ec8fee1 to d584f92 Compare April 8, 2019 08:50
@muan muan closed this in #26 Nov 5, 2019
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.

2 participants