Newer Version Available
onUtilityClick() for Lightning Experience
Registers an eventHandler for the utility. This
eventHandler is called when the utility is
clicked.
Keep the following things in mind when working with this method.
- The method is supported in Lightning apps with standard and console navigation.
- You can use this method to register multiple callbacks per utilityItem when executed sequentially.
- You can’t remove registered callbacks.
Arguments
| Name | Type | Description |
|---|---|---|
| utilityId | string | The ID of the utility for which to register the callback. Optional when called within a utility. |
| eventHandler | function | The JavaScript function that's called when the utility is clicked. |
Sample Code
This component has a button that, when pressed, registers an eventHandler function for the enclosing utility.
Component code:
1<aura:component implements="flexipage:availableForAllPageTypes" access="global">
2 <lightning:utilityBarAPI aura:id="utilitybar" />
3 <lightning:button label="Register Event Handler" onclick="{!c.registerUtilityClickHandler}"/>
4</aura:component>Controller code:
1({
2 registerUtilityClickHandler: function(component, event, helper){
3 var utilityBarAPI = component.find("utilitybar");
4 var eventHandler = function(response){
5 console.log(response);
6 };
7
8 utilityBarAPI.onUtilityClick({
9 eventHandler: eventHandler
10 }).then(function(result){
11 console.log(result);
12 }).catch(function(error){
13 console.log(error);
14 });
15 }
16})Response
This method returns a promise that, upon success, resolves to true, and is rejected on error. The eventHandler expects a response JSON object containing the following fields.
| Name | Type | Description |
|---|---|---|
| utilityId | string | The ID of the utilityBar item button that was clicked. |
| panelVisible | boolean | False if the utility item panel is hidden after the button is clicked. True if the utility item panel is visible after the button is clicked. |