2

I'd like to display a "header" for those instances where my Lightning component is not displayed in a tab, but directly on the page. Is there a way to determine if a Lightning component is being displayed in a tab?

enter image description here

  • What is the difference here between a tab and a page? Is your tab a custom tab that you have created and is the page a record page? – Jayant Das May 14 at 13:51
  • @JayantDas the tab would be the Standard Lightning component you add to a Lightning page. Its called "Tabs". – Michael Sobczak May 14 at 14:13
  • @JayantDas I added a picture to show what I'm referring to. – Michael Sobczak May 14 at 14:18
3
+50

Let me offer you another approach.

Instead of trying to figure out where a component is dropped, think about exposing a design attribute on your component that will allow users to show or hide the header manually when they manipulate it in the App Builder.

demoComponent.cmp

<aura:component implements="flexipage:availableForAllPageTypes" access="global" >

    <aura:attribute name="showHeader" type="boolean" />

    <aura:if isTrue="{!v.showHeader}">
        <h1>This is a header</h1>
    </aura:if>

    <div>Something else</div>

</aura:component>

demoComponent.design

<design:component>
    <design:attribute name="showHeader" label="Show Header?" default="false"/>
</design:component>

The above code will result in Show Header? property being available to a user in the Lightning App Builder:

enter image description here

  • 1
    I like this approach. I hadn't used design attributes much, but this makes a lot of sense in this context. Thanks! – Michael Sobczak Jun 5 at 20:29
0

So in layman's term, you want to determine what is the parent of your child component.

No, This is not possible and this should never be possible as this contains a great security risk. Imagine any rogue app exchange application reading the parent's component data(in your case tabs) and doing the malicious operation.

The aura framework will never have a way for you to get the parent component. That breaks encapsulation.

That being said, why should a component behave differently based on where its dropped? The component should expose a few properties which parent can fill in and change behavior if needed.

  • I'm not sure what you are saying makes sense. Using the workspaceAPI from within an Aura Lightning component, I can get tabs in the current console. Would that not be a security risk, as you put it? – Michael Sobczak Jun 5 at 20:11
  • Workspace API allows you to open, close tabs but does not allow you read content. On little subset of funtions which wont posses security risk are allowed – Pranay Jaiswal Jun 5 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.