I have a custom element and would like to detect clicks outside of it. For example
<dom-module id="simple-element">
<style>
</style>
<template>
<content></content>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'simple-element',
listeners: {
'tap': 'regularTap'
},
regularTap: function() {
console.log("i was tapped");
}
});
})();
</script>
Is there an event where I can listen to which will tell me when user has clicked outside of the element? Thanks.
I've found a simpler solution haven't tested it on all browsers yet, but makes sense. So I add a global listener to window, and a listener to the custom element. This way click inside will call both, click outside will only call global..
Something along these lines should do what you want:
Modified the code so that it actually works:
You can use a behavior like this: