user2935300
user2935300

Reputation: 101

Can Polymer element add an event listener to it's parent element when inside shadow DOM?

I would like to make a context menu element that automatically adds a contextmenu listener to it's parent element (so it can be expanded when the parent is right-clicked). I managed to do it by looking up this.parentNode when the element sits in a regular DOM hierarchy. However, when inside a shadow DOM, this.parentNode points to #document-fragment and there doesn't seem to be a way to pierce through that barrier. Is there something I am missing here?

Upvotes: 2

Views: 880

Answers (1)

Scott Miles
Scott Miles

Reputation: 11027

there doesn't seem to be a way to pierce through that barrier

In Polymer, there is a host property on the Shadow DOM document-fragment that points to the owning element.

Upvotes: 2

Related Questions