onUtilityClick() for Lightning Experience

Registers an eventHandler for the utility. This eventHandler is called when the utility is clicked.

Consider the following guidelines 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.

The method provides the same arguments for both Aura Components and Lightning Web Components (LWC).

For LWC, optional parameters are passed into an object as the last argument of the method.

NameTypeDescription
utilityIdstringThe ID of the utility for which to register the callback. Optional when called within a utility using Aura Components. Always required for LWC.
eventHandlerfunctionThe JavaScript function that’s called when the utility is clicked.

This component handles a utility click using the EnclosingUtilityId wire adapter.

To make your component available for use in a utility bar, specify the lightning__UtilityBar target in the component’s configuration file.

Returns a promise that resolves to true if successful. The promise is rejected on error.

This component has a button that, when pressed, registers an eventHandler function for the enclosing utility.

Component code:

Controller code:

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.

NameTypeDescription
utilityIdstringThe ID of the utilityBar item button that was clicked.
panelVisiblebooleanFalse 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.