I have a web component (Polymer 3) that is embedded in other components and want to "sense" clicks outside of it. For example, in React I would do something like this inside of the component:
document.addEventListener('click', this.handleClickOutside, true);
public handleClickOutside = event => {
const domNode = ReactDOM.findDOMNode(this);
if (!domNode || !domNode.contains(event.target)) {
//logic
}
}
Above we simply add a click event, and then check if the event have targeted the current component via a reference.
As its "react syntax" I need to to something similar but for web components. I need a reference to the current web component. I have tried:
const domNode = this;
And
const domNode = this.$['my-component'];
without luck. Any help?