Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Event Handler Behavior for Active Components
This workaround uses the offsetParent property for the component to get its handlers while they’re visible. The workaround is good only if the component definition has an HTML element in it.
This component includes an event handler and some HTML.
1<!--myComponent.cmp-->
2<aura:component>
3 <aura:handler event="c:appEvent" action="{!c.onEvent}>
4 <h1>This component has a handler</h1>
5</aura:component>Here’s the client-side controller that uses the offsetParent property to get the component’s handlers while they’re still visible.
1/* myComponentController.js */
2({
3 onEvent: function(component, event, helper) {
4 var elem = component.getElement();
5 if (elem && elem.offsetParent !== null) {
6 // event handling logic here
7 }
8 }
9})