How to Create a Customizable Tabs for Salesforce Lightning Component Page Using Component Controller JavaScript | how to add/remove tabs in Salesforce lightning component

1,284 views


Hey guys, today in this post we are going to learn about how to create a Customizable Tabs for Salesforce Lightning Component pages using component controller Javascript.

Files we used in this post example:-

customTabApp.app Lightning Application It is used for call the component to preview on browser.

customTabCmp.cmp

Lightning Component It is used for create a custom tabs on lightning component .

customTabCmpController.js

JavaScript Controller File It is used for click function for show and hide the custom tabs section.
customTabCmp.css Component Style CSS It is used for create custom Style CSS for active tab highlight section.

Live Demo

Create a Custom Tab for Salesforce Lightning Component -- w3web.net

 

 

You can download file directly from github by Click Here.

 

 

Other related post that would you like to learn in Salesforce

 

Step 1:- Create Lightning Application : customTabApp.app

From Developer Console >> File >> New >> Lightning Application

customTabApp.app [Component Application File]

  1.    <aura:application extends="force:slds">
  2. 	<c:customTabCmp/>
  3. </aura:application>

Step 2:- Create Lightning Component : customTabCmp.cmp

From Developer Console >> File >> New >> Lightning Component

customTabCmp.cmp [Lightning Component File]

  1.    <aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
  2. 	<div class="slds slds-p-around--medium">
  3.        <div class="slds-tabs_default" id="sldsTabItemOver">          
  4.           <div class="slds-tabs_default__content slds-show" role="tabpanel">
  5.             <div class="slds-tabs_scoped">
  6.               <ul class="slds-tabs_scoped__nav">
  7.                 <li class="slds-tabs_scoped__item slds-is-active" id="tabItem3webnet0">
  8.                   <a class="slds-tabs_scoped__link" href="javascript:void(0);" name="tabItem3webnet0" onclick="{!c.tabActionw3webnet}">Blog</a>
  9.                 </li>
  10.                 <li class="slds-tabs_scoped__item" id="tabItem3webnet1">
  11.                   <a class="slds-tabs_scoped__link" href="javascript:void(0);" name="tabItem3webnet1" onclick="{!c.tabActionw3webnet}">Tutorial</a>
  12.                 </li>
  13.                 <li class="slds-tabs_scoped__item" id="tabItem3webnet2">
  14.                   <a class="slds-tabs_scoped__link" href="javascript:void(0);" name="tabItem3webnet2" onclick="{!c.tabActionw3webnet}">Technical Guide</a>
  15.                 </li>
  16.  
  17.                  <li class="slds-tabs_scoped__item" id="tabItem3webnet3">
  18.                   <a class="slds-tabs_scoped__link" href="javascript:void(0);" name="tabItem3webnet3" onclick="{!c.tabActionw3webnet}">JQuery</a>
  19.                 </li> 
  20.  
  21.                  <li class="slds-tabs_scoped__item" id="tabItem3webnet4">
  22.                   <a class="slds-tabs_scoped__link" href="javascript:void(0);" name="tabItem3webnet4" onclick="{!c.tabActionw3webnet}">Sitemap</a>
  23.                 </li> 
  24.  
  25.                 <li class="slds-tabs_scoped__item" id="tabItem3webnet5">
  26.                   <a class="slds-tabs_scoped__link" href="javascript:void(0);" name="tabItem3webnet5" onclick="{!c.tabActionw3webnet}">About Us</a>
  27.                 </li> 
  28.  
  29.                  <li class="slds-tabs_scoped__item" id="tabItem3webnet6">
  30.                   <a class="slds-tabs_scoped__link" href="javascript:void(0);" name="tabItem3webnet6" onclick="{!c.tabActionw3webnet}">Contact Us</a>
  31.                 </li> 
  32.  
  33.               </ul>
  34.  
  35.               <div id="activetabItem3webnet0" class="slds-tabs_scoped__content slds-show">
  36.                   <div class="tabContent">
  37.                       <div class="postImage">					
  38.                           <a href="https://www.w3web.net/blogging-complete-guide-for-beginners/">
  39.                               <img src="https://www.w3web.net/wp-content/uploads/2020/07/blogGuide.png" width="200" height="150"/>
  40.                           </a>
  41.                       </div> 
  42.                       <p><b>How to start a blog for free that makes money | A simple 8 easy guide step-by-step for beginners</b></p><br/>
  43.                       <p>In this post we are going to learn about How to start a blog and make money. Easy Guide Step-By-Step for Beginners follow given points.</p><br/>
  44.                       <p>Blog is a platform where you can share your personal experience that you have in expertise. You can start it from such like your Hobbies, Business, Sports, Medical Equipment, Education, Network Marketing etc..</p><br/>
  45.                       <p>So think about yourself that in which fields you are much more knowledge and create a blog on the same field.</p><br/>
  46.  
  47.                       <p>There are 8 easy steps to start a blogging...<span class="readMore"><a href="https://www.w3web.net/blogging-complete-guide-for-beginners/">Read more...</a></span></p>
  48.                   </div>
  49.                </div>
  50.               <div id="activetabItem3webnet1" class="slds-tabs_scoped__content slds-hide">
  51.                   <div class="tabContent">
  52.                       <div class="postImage">					
  53.                           <a href="https://www.w3web.net/update-count-of-child-record-based-on-parent-object-value/">
  54.                               <img src="https://www.w3web.net/wp-content/uploads/2020/08/employeeSizeTrigger.png" width="200" height="150"/>
  55.                           </a>
  56.                       </div> 
  57.                       <p><b>Trigger to update count of child records with custom field of parent object</b></p><br/>
  58.                       <p>Hey guys, today in this post we are going to learn about how to update count of child records with custom field value into parent object using trigger map list in Salesforce.</p><br/>
  59.                       <p>Real time scenarios:- Write a trigger on parent object where create a custom field as Employee (Number type).</p><br/>
  60.                       <p>If user insert the parent record, the child record should be automatic inserted equal to the same value of employee...<span class="readMore"><a href="https://www.w3web.net/update-count-of-child-record-based-on-parent-object-value/">Read more...</a></span></p>
  61.                   </div>
  62.                </div>
  63.               <div id="activetabItem3webnet2" class="slds-tabs_scoped__content slds-hide">
  64.                   <div class="tabContent">
  65.                       <div class="postImage">					
  66.                           <a href="https://www.w3web.net/how-to-voice-typing-in-computer-from-mobile/">
  67.                               <img src="https://www.w3web.net/wp-content/uploads/2020/07/remote-app2-1-1.png" width="200" height="150"/>
  68.                           </a>
  69.                       </div> 
  70.                       <p><b>How to voice typing in computer from mobile?</b></p><br/>
  71.                       <p>Many people writing a Blog or Article. There can be multiple pages in a single article, if you have not good hand typing speed you will be face so many difficulty.</p><br/>
  72.                       <p>If you want to write a article English or Hindi very fast than go through the “Remote Mouse App”. It is a free app and available on google app store, or you can download from your laptop directly go through this link “https://www.remotemouse.net/”. This App helps you to write a article English/Hindi very fast and save the plenty of time....<span class="readMore"><a href="https://www.w3web.net/how-to-voice-typing-in-computer-from-mobile/">Read more...</a></span></p>
  73.                   </div>
  74.                </div>
  75.               <div id="activetabItem3webnet3" class="slds-tabs_scoped__content slds-hide">
  76.                   <div class="tabContent">
  77.                       <div class="postImage">					
  78.                           <a href="https://www.w3web.net/custom-sidebar-navigation-menu-with-submenu/">
  79.                               <img src="https://www.w3web.net/wp-content/uploads/2020/08/sidebarNavigationFeature.png" width="200" height="150"/>
  80.                           </a>
  81.                       </div>                       
  82.                       <p><b>How to Build a Custom Left Sidebar Navigation Menu with Submenu using HTML, CSS and JQuery</b></p><br/>
  83.                       <p>In this post we are going to learn about how to create a custom left sidebar Navigation Menu with Submenu using HTML, CSS and JQuery...<span class="readMore"><a href="https://www.w3web.net/custom-sidebar-navigation-menu-with-submenu/">Read more...</a></span></p>
  84.                   </div>
  85.                </div>
  86.               <div id="activetabItem3webnet4" class="slds-tabs_scoped__content slds-hide">
  87.                   <div class="tabContent">
  88.                       <div class="postImage">					
  89.                           <a href="https://www.w3web.net/all-published-post/">
  90.                               <img src="https://www.w3web.net/wp-content/uploads/2020/08/sitemap.png" width="200" height="150"/>
  91.                           </a>
  92.                       </div> 
  93.                       <p><b>Sitemap</b></p>
  94.                       <p>Here you can find all of the published post on <a href="https://www.w3web.net/">w3web.net</a></p><br/>
  95.                       <p><span><a href="https://www.w3web.net/how-to-validate-child-component-from-parent-component/">How to validate child component from parent component on click button using aura method in lightning component</a></span></p><br/>
  96.                       <p><span><a href="https://www.w3web.net/expand-all-collapse-all-rows-in-lightning-component/">Create custom expand all/ collapse all for accordion section rows table based in lightning component</a></span></p><br/>
  97.                       <p><span><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/">Editing row, Saving row and Removing rows Dynamically in Lightning component Salesforce</a></span></p><br/>
  98.                       <p><span class="readMore"><a href="https://www.w3web.net/all-published-post/">Read more...</a></span></p>
  99.                   </div>
  100.                </div>
  101.               <div id="activetabItem3webnet5" class="slds-tabs_scoped__content slds-hide">
  102.                   <div class="tabContent">
  103.                       <div class="postImage">					
  104.                           <a href="https://www.w3web.net/about-us/">
  105.                               <img src="https://www.w3web.net/wp-content/uploads/2020/08/aboutus.png" width="200" height="150"/>
  106.                           </a>
  107.                       </div> 
  108.                       <p><b>About Us</b></p>
  109.                       <p><b><a href="https://www.w3web.net/">w3web.net</a></b> is the place where you can learn step-by-step about Blog, WordPress, Salesforce Lightning Component, Lightning Web Component (LWC), Visualforce, Technical of Computer Application, Salesforce Plugin, JavaScript, Jquery, CSS, Computer and Accessories, Software Configuration, Customization, Development and much more…</p><br/>
  110.                       <p>I am Web and Mobile application developer and sharing knowledge is my passion. Web application development is my interest but it is not biggere then my dream....<span class="readMore"><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/">Read more...</a></span></p>
  111.                   </div>
  112.                </div>
  113.               <div id="activetabItem3webnet6" class="slds-tabs_scoped__content slds-hide">
  114.                   <div class="tabContent">
  115.                       <div class="postImage">					
  116.                           <a href="https://www.w3web.net/contact-us/">
  117.                               <img src="https://www.w3web.net/wp-content/uploads/2020/08/contactUs.png" width="200" height="150"/>
  118.                           </a>
  119.                       </div> 
  120.                       <p><b>Contact Us</b></p>
  121.                       <p>Thank you for contact with us. you can write us at the below contact form for any of your queries / clarifications.</p><br/>
  122.                       <p>You can also email us for a faster response. <b>E-mail:- vijayk085@gmail.com</b>...<span class="readMore"><a href="https://www.w3web.net/contact-us/">Read more...</a></span></p>
  123.                   </div>
  124.                </div>                  
  125.             </div>
  126.           </div>
  127.  
  128.         </div>
  129.  
  130. <br/> <br/>
  131.    <!--Start RelatedTopics Section-->
  132. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  133.  
  134.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click  <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
  135.  
  136.             <br/><br/>
  137.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like →</span> </strong></p>
  138.             <div style="display:block; overflow:hidden;"> 
  139.                 <div style="width: 50%; float:left; display:inline-block">
  140.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  141.                         <li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
  142.                         <li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
  143.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
  144.                         <li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
  145.                         <li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
  146.                     </ul>
  147.             </div>
  148.  
  149.             <div style="width: 50%; float:left; display:inline-block">
  150.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  151.                         <li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
  152.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
  153.                         <li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
  154.                         <li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
  155.                         <li><a href="https://www.w3web.net/update-parent-object-from-child/" target="_blank" rel="noopener noreferrer">update parent field from child using apex trigger</a></li>
  156.                     </ul>
  157.                 </div>
  158.                <div style="clear:both;"></div> 
  159.                <br/>
  160.                 <div class="youtubeIcon">
  161.                     <a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
  162.                 </div>
  163.     </div>
  164.  
  165. </div>
  166.  
  167.   <!--End RelatedTopics Section-->
  168.  
  169.     </div>
  170. </aura:component>

Step 3:- Create Lightning Component : customTabCmpController.js

From Developer Console >> File >> New >> Lightning Component >> JavaScript Controller

customTabCmpController.js [JavaScript Controller]

  1.    ({
  2. 	tabActionw3webnet : function(component, event, helper) {
  3. 		var thisObj = event.target.name;
  4.         var sldsTabItemOver = document.getElementById('sldsTabItemOver');
  5.         var scopedItemAll =  sldsTabItemOver.querySelectorAll('.slds-tabs_scoped__item');
  6.         var scopedContent =  sldsTabItemOver.querySelectorAll('.slds-tabs_scoped__content');
  7.  
  8.         var isActive = document.getElementById(thisObj).classList.contains('slds-is-active');
  9.  
  10.         for(var i=0; i<scopedItemAll.length; i++){
  11.             scopedItemAll[i].classList.remove('slds-is-active');
  12.             scopedContent[i].classList.add('slds-hide');
  13.         }
  14.  
  15.         document.getElementById(thisObj).classList.add('slds-is-active'); 
  16.         document.getElementById('active'+thisObj).classList.remove('slds-hide');
  17.         document.getElementById('active'+thisObj).classList.add('slds-show');
  18.  
  19. 	},
  20. })

Step 4:- Create Lightning Component Style: customTabCmp.css

From Developer Console >> File >> New >> Lightning Component >> Component Style CSS

customTabCmp.css [Style CSS]

  1.   .THIS {
  2. }
  3. .THIS  .slds-tabs_scoped__item.slds-is-active .slds-tabs_scoped__link{color:#b70e01; text-decoration:none;}
  4. .THIS .tabContent{display:block; padding:5px 0 5px 0px; font-size:14px; overflow: hidden;}
  5. .THIS .tabContent .postImage{display: inline-block; float: left; margin-right: 10px;}
  6. .THIS .readMore{font-size:14px; font-weight:bold; display:inline-block; padding:0 0 0 10px;}
  7. .THIS .readMore a{color:#ff0000; text-decoration:none;}
  8. .THIS .readMore a:hover{color:#04a5ca; text-decoration:underline;}


custom tab of lightning component -- w3web.net


 
 

Further post that would you like to learn in Salesforce

 
 

 

 

FAQ (Frequently Asked Questions)

What are the three different custom tabs you can create in Salesforce?

You can create three different kinds of custom tabs: custom object tabs, Web tabs, and Visualforce page tabs.

How do I add a custom object to a tab in Salesforce lightning?

From Setup, in the Quick Find box, enter Tabs , then select Tabs. Click New in the Custom Object Tabs related list. Select the custom object to appear in the custom tab. If you haven't created the custom object, click create a new custom object now and follow the instructions in Create a Custom Object.

What are tabs in Salesforce lightning?

Custom tabs let you display custom object data or other web content in Salesforce. When you add a custom tab to an app in Salesforce Classic, it appears as a tab. When you add a custom tab to an app in Lightning Experience, it appears as an item in the app's navigation bar and in the App Launcher.

Related Topics | You May Also Like

Our Free Courses →

👉 Download App to Get Free Course →

📌 Salesforce Administrators

📌 Salesforce Lightning Flow Builder

📌 Salesforce Record Trigger Flow Builder

👉 Download App to Get Free Course →

📌 Aura Lightning Framework

📌 Lightning Web Component (LWC)

📌 Rest APIs Integration

 
 
🌩️ Download App to Get Free Course Access: -

Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment