Is there a way I can detect from my lightning component whether the user is utilizing a utility bar or not?
It covers the bottom part of my application and I need to be able to resize the application so that the bottom edge of the application is still usable.
-
Depends how you define 'utilizing', you can of course develope an expandable-collapsible section for the utility bar.– Santanu HalderCommented Jun 9, 2017 at 5:54
-
@SantanuHalder : My lightning application takes up the entire browser window, and if there is a utility bar covering the bottom part of the application, I would like to resize it to be slightly smaller in the y-axis.– Jason LeeCommented Jun 9, 2017 at 15:37
Add a comment
|
2 Answers
With the Lightning Console API available in Winter ’18, one can access information about the utility bar. Try the following:
Component markup
<aura:component implements="flexipage:availableForAllPageTypes" access="global">
<!-- attributes -->
<lightning:utilityBarAPI aura:id="utilitybar" />
<aura:attribute name="hasUtilityBar" type="Boolean" default="false" />
<!-- event handlers -->
<aura:handler name="init" value="{! this }" action="{! c.init }" />
<p>Is there a utility bar? {! v.hasUtilityBar ? 'Yes' : 'No' }</p>
</aura:component>
Controller:
({
init: function (component, event, helper) {
var utilityAPI = component.find('utilitybar');
utilityAPI.getAllUtilityInfo().then(function (response) {
if (typeof response !== 'undefined') {
component.set('v.hasUtilityBar', true);
} else {
component.set('v.hasUtilityBar', false);
}
});
}
});
Reference the Lightning Console API documentation.
In response to the above answer, typeof response !== 'undefined'
comes back as as an empty array even if the utility bar is not present, so I needed to use:
if (response && response.length > 0) {
component.set('v.hasUtilityBar', true);
}
(I don't have enough reputation to comment on an answer.)