function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jojoforcejojoforce 

lightning:tabset child components within a tab is undefined until tab is activated

I'm encountering a weird situation in using lightning:tabset, apparently, if the user has not yet navigated (or activated) a tab, the child component in it will be undefined thus any attributes in that component will not be accessible. 


For example... If I have not activated tab2 (meaning, the user did not click tab2 yet) then component.find('tab2') will be undefined. 
 
<lightning:tabset>
 <lightning:tab tab1>
    <c:component_in_tab1 aura:id="tab1" />
 </lightning:tab>

 <lightning:tab tab2>
    <c:component_in_tab2 aura:id="tab2" />     
  </lightning:tab>
</lightning:tabset>


 
var cmp = component.find('tab2');   // THIS THROWS UNDEFINED
var dataAttribute = cmp.get('v.myAttribute');

 
Raj VakatiRaj Vakati
Try some thing like below 
 
<lightning:tabset>
 <lightning:tab tab1 id="tab11111">
    <c:component_in_tab1 aura:id="tab1" />
 </lightning:tab>

 <lightning:tab tab2 id="tab2222">
    <c:component_in_tab2 aura:id="tab2" />     
  </lightning:tab>
</lightning:tabset>



var tab = event.getSource();
        switch (tab.get('v.id')) {
            case 'tab11111' :
			
			
                break;
            case 'tab2222' :
			var cmp = component.find('tab2');   // THIS THROWS UNDEFINED
var dataAttribute = cmp.get('v.myAttribute');
			
                break;
        }

 
Pankaj Nayak 13Pankaj Nayak 13
Hi, Did you get the answer for this ?