Build a vertical navigation to show/hide a div container that display respective selected contents when clicking on the list of links Uses of “lightning-vertical-navigation” elements in Salesforce Lightning Web Component — LWC | how to create vertical navigation bar to display selected menus using elements of “lightning-vertical-navigation” & “lightning-vertical-navigation-item” in Salesforce LWC

3,916 views

Hey guys, today in this post we are going to learn about How to build a vertical navigation to show/hide a div container that display respective selected contents when clicking on the list of links Uses of “lightning-vertical-navigation” elements in Salesforce Lightning Web Component — LWC.

A lightning-vertical-navigation component represents a list of links that’s only one level deep, with support for overflow sections that collapse and expand. The overflow section must be created using lightning-vertical-navigation-overflow and does not adjust automatically based on the view port. To know more about vertical navigation, Use this link.

This component inherits styling from vertical navigation in the Lightning Design System.

 

Files we used in this post example →

lwcVerticalNavigation.html LWc HTML File Template HTML file to create vertical navigation in Salesforce Lightning Web Component (LWC)
lwcVerticalNavigation.js LWC JavaScript File It’s hold a javascript on click function to display the selected navigation contents in lwc.
lwcVerticalNavigation.js-meta.xml XML Meta File It is used to where this lightning web component file you want to display as lightning__AppPage, lightning__RecordPage, lightning__HomePage.
lwcVerticalNavigation.css Style CSS It is used to fixed the alignment of navigation tab container.
lwcVerticalNavigationApp.app Lightning Application It is used for call the component and preview on browser.

Final Output →

lwc Vertical Navigation display selected content -- w3web.net

 

You can download file directly from github by Click Here.

 
 

Other related post that would you like to learn in Salesforce

  • Find the below steps

Create Lightning Web Component HTML →

Step 1:- Create Lightning Web Component : lwcVerticalNavigation.html

SFDX:Lightning Web Component >> New >> lwcVerticalNavigation.html

lwcVerticalNavigation.html [Lightning Web Component HTML]

  1.    <template>
  2. <lightning-card>
  3. <div class="slds-p-around_medium">
  4.     <h3 class="slds-text-heading_medium"><lightning-icon icon-name="custom:custom21" size="small"></lightning-icon> <strong style="color:#270086; font-size:13px;"> Create Vertical Navigation in Lightning Web Component (LWC) </strong></h3>
  5.     <br/>
  6.     <lightning-layout>           
  7.         <lightning-layout-item>
  8.             <lightning-vertical-navigation selected-item={selectedItem} onselect={changeHandleAction} class="navigation">
  9.                 <lightning-vertical-navigation-section label="Vertical Navigation">
  10.                     <lightning-vertical-navigation-item label="Tutorial" name="tutorial"></lightning-vertical-navigation-item>
  11.                     <lightning-vertical-navigation-item label="Integration" name="integration"></lightning-vertical-navigation-item>
  12.                     <lightning-vertical-navigation-item label="Visualforce" name="visualforce"></lightning-vertical-navigation-item>
  13.                     <lightning-vertical-navigation-item label="Trigger" name="trigger"></lightning-vertical-navigation-item>
  14.                     <lightning-vertical-navigation-item label="Jquery/Javascript" name="jqueryJavascript"></lightning-vertical-navigation-item>
  15.                     <lightning-vertical-navigation-item label="Salesforce LWC" name="salesforceLwc"></lightning-vertical-navigation-item>
  16.                 </lightning-vertical-navigation-section>
  17.             </lightning-vertical-navigation>
  18.         </lightning-layout-item>
  19.  
  20.         <lightning-layout-item padding="around-medium">
  21.             <h2 class="slds-section-title--divider" style="background:#eee; margin-bottom:10px;"><strong>You Are Viewing: <span style="color:#0000ff;">{currentContent}</span></strong></h2>
  22.  
  23.             <template if:true={tutorialValue}>                      
  24.                 <div class="tabContent">                        
  25.                     <div class="postImage">					
  26.                         <a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">
  27.                             <img src="https://www.w3web.net/wp-content/uploads/2020/08/aboutus.png" width="300" height="200"></img>
  28.                         </a>
  29.                     </div> 
  30.                     <div class="imgRt"> 
  31.                     <h3 class="slds-text-heading_small slds-text-color--error"><strong>Tutorial W3web</strong></h3> 
  32.                     <p class="titleTag"><b><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">Easy to learn step-by-step online Salesforce tutorial from w3web.net</a></b></p>
  33.                     <p><strong>w3web.net</strong> is the place where you can learn step-by-step about Blog, WordPress, Salesforce Lightning Component, Lightning Web Component (LWC),</p>                     
  34.                     <p>Visualforce, Technical of Computer Application, Salesforce Plugin, JavaScript, Jquery, CSS, Computer and Accessories, Software Configuration, Customization, Development and much<span class="readMore"><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer"> more →</a></span></p>
  35.                     </div>    
  36.                 </div>
  37.             </template>
  38.  
  39.             <template if:true={integrationValue}>
  40.                 <div class="tabContent">                        
  41.                     <div class="postImage">					
  42.                         <a href="https://www.w3web.net/create-node-rest-api-to-insert-update-delete-from-soql/" target="_blank" rel="noopener noreferrer">
  43.                             <img src="https://www.w3web.net/wp-content/uploads/2021/09/nodeApiFeature.png" width="300" height="200"></img>
  44.                         </a>
  45.                     </div> 
  46.                     <div class="imgRt"> 
  47.                     <h3 class="slds-text-heading_small slds-text-color--error"><strong>REST API Integration</strong></h3> 
  48.                     <p class="titleTag"><b><a href="https://www.w3web.net/create-node-rest-api-to-insert-update-delete-from-soql/" target="_blank" rel="noopener noreferrer">How to insert, update, retrieve and Delete Record from Node js Rest Api Using Express JS, pool, pg module and localserver in Salesforce (SOQL).</a></b></p>
  49.                     <p>Create Node js Rest Api to get, insert, update and delete records from SOQL Using.</p>                     
  50.                     <p>Today in this post we are going to learn about How to Create Node js Rest Api to get, insert, update and delete records from SOQL Using Express JS, Install pool database, Install pg and Install localserver to Start port terminal and project structure setup.<span class="readMore"><a href="https://www.w3web.net/create-node-rest-api-to-insert-update-delete-from-soql/" target="_blank" rel="noopener noreferrer"> more →</a></span></p>
  51.                     </div>    
  52.                 </div>
  53.             </template>
  54.  
  55.             <template if:true={visualforceValue}>
  56.                 <div class="tabContent">                        
  57.                     <div class="postImage">					
  58.                         <a href="https://www.w3web.net/visualforce-page-to-return-data-from-multiple-custom-object/" target="_blank" rel="noopener noreferrer">
  59.                             <img src="https://www.w3web.net/wp-content/uploads/2021/05/vfpMultipleObjects.png" width="300" height="200"></img>
  60.                         </a>
  61.                     </div> 
  62.                     <div class="imgRt"> 
  63.                     <h3 class="slds-text-heading_small slds-text-color--error"><strong>Salesforce Visualforce Page</strong></h3> 
  64.                     <p class="titleTag"><b><a href="https://www.w3web.net/visualforce-page-to-return-data-from-multiple-custom-object/" target="_blank" rel="noopener noreferrer">How to fetch data from multiple different object in visualforce page.</a></b></p>
  65.                     <p>Create visualforce page to retrieve data from multiple custom objects using custom controller wrapper class.</p>                     
  66.                     <p>Today in this post we are going to learn about how to retrieve data from multiple custom objects using custom controller wrapper class and display data in a table of VF page in Salesforce..<span class="readMore"><a href="https://www.w3web.net/visualforce-page-to-return-data-from-multiple-custom-object/" target="_blank" rel="noopener noreferrer"> more →</a></span></p>
  67.                     </div>    
  68.                 </div>
  69.             </template>
  70.  
  71.             <template if:true={triggerValue}>
  72.                 <div class="tabContent">                        
  73.                     <div class="postImage">					
  74.                         <a href="https://www.w3web.net/trigger-to-check-duplicate-email-on-lead/" target="_blank" rel="noopener noreferrer">
  75.                             <img src="https://www.w3web.net/wp-content/uploads/2021/07/duplicateEmailCheckLeadFeature.png" width="300" height="200"></img>
  76.                         </a>
  77.                     </div> 
  78.                     <div class="imgRt"> 
  79.                     <p class="titleTag"><b><a href="https://www.w3web.net/trigger-to-check-duplicate-email-on-lead/" target="_blank" rel="noopener noreferrer">Preventing duplicate records of contact based on multiple fields.</a></b></p>
  80.                     <p>Write a trigger on lead to prevent duplicate records based on lead email Whenever the records is inserted Or updated using apex class.</p>                     
  81.                     <p>Today in this post we are going to learn about How to Check Duplicate Email on Lead Object in Salesforce. Write a trigger on lead to prevent duplicate records.<span class="readMore"><a href="https://www.w3web.net/trigger-to-check-duplicate-email-on-lead/" target="_blank" rel="noopener noreferrer"> more →</a></span></p>
  82.                     </div>    
  83.                 </div>
  84.             </template>
  85.  
  86.             <template if:true={jqueryJavascriptValue}>
  87.                 <div class="tabContent">                        
  88.                     <div class="postImage">					
  89.                         <a href="https://www.w3web.net/image-gallery-with-a-jorizontal-thumbnail-carousel/" target="_blank" rel="noopener noreferrer">
  90.                             <img src="https://www.w3web.net/wp-content/uploads/2020/10/imageGallerySliderFeature.png" width="300" height="200"></img>
  91.                         </a>
  92.                     </div> 
  93.                     <div class="imgRt"> 
  94.                     <h3 class="slds-text-heading_small slds-text-color--error"><strong>Salesforce Visualforce Page</strong></h3> 
  95.                     <p class="titleTag"><b><a href="https://www.w3web.net/image-gallery-with-a-jorizontal-thumbnail-carousel/" target="_blank" rel="noopener noreferrer">Create multiple image slider in jquery.</a></b></p>
  96.                     <p>Write a trigger on lead to prevent duplicate records based on lead email Whenever the records is inserted Or updated using apex class.</p>                     
  97.                     <p>Today in this post we are going to learn about Create a Custom Image Gallery With a Horizontal Thumbnail Carousel Simply using Custom JQuery Small Function and CSS for Create Image Gallery.<span class="readMore"><a href="https://www.w3web.net/image-gallery-with-a-jorizontal-thumbnail-carousel/" target="_blank" rel="noopener noreferrer"> more →</a></span></p>
  98.                     </div>    
  99.                 </div>
  100.             </template>
  101.  
  102.             <template if:true={salesforceLwcValue}>
  103.                 <div class="tabContent">                        
  104.                     <div class="postImage">					
  105.                         <a href="https://www.w3web.net/lwc-get-customize-custom-metadata-in-apex/" target="_blank" rel="noopener noreferrer">
  106.                             <img src="https://www.w3web.net/wp-content/uploads/2021/09/lwcFetchCustomMetaDataFeature.png" width="300" height="200"></img>
  107.                         </a>
  108.                     </div> 
  109.                     <div class="imgRt"> 
  110.                     <h3 class="slds-text-heading_small slds-text-color--error"><strong>Salesforce LWC</strong></h3> 
  111.                     <p class="titleTag"><b><a href="https://www.w3web.net/lwc-get-customize-custom-metadata-in-apex/" target="_blank" rel="noopener noreferrer">how to get custom Metadata in lwc using Apex</a></b></p>
  112.                     <p>How to fetch/customize the custom metadata and display the list of metadata in lightning component using Apex class in Salesforce Lightning Web Component — LWC.</p>                     
  113.                     <p>Today in this post we are going to learn about How to How to fetch/customize the custom metadata and display the list of metadata in lightning component using Apex class in Salesforce Lightning Web Component — LWC.<span class="readMore"><a href="https://www.w3web.net/lwc-get-customize-custom-metadata-in-apex/" target="_blank" rel="noopener noreferrer"> more →</a></span></p>
  114.                     </div>    
  115.                 </div>
  116.             </template>
  117.  
  118.  
  119.         </lightning-layout-item>
  120.     </lightning-layout>
  121. <br/><br/>
  122.     <br/>
  123.    <!--Start RelatedTopics Section-->
  124. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  125.  
  126.             <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>
  127.  
  128.             <br/><br/>
  129.             <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>
  130.             <div style="display:block; overflow:hidden;"> 
  131.                 <div style="width: 50%; float:left; display:inline-block">
  132.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  133.                         <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>
  134.                         <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>
  135.                         <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>
  136.                         <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>
  137.                         <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>
  138.                     </ul>
  139.             </div>
  140.  
  141.             <div style="width: 50%; float:left; display:inline-block">
  142.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  143.                         <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>
  144.                         <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>
  145.                         <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>
  146.                         <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>
  147.                         <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>
  148.                     </ul>
  149.                 </div>
  150.                <div style="clear:both;"></div> 
  151.                <br/>
  152.                 <div class="youtubeIcon">
  153.                     <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>
  154.                 </div>
  155.     </div>
  156.  
  157. </div>
  158.  
  159.   <!--End RelatedTopics Section-->
  160.  
  161. </div>
  162. </lightning-card> 
  163. </template>

Create Lightning Web Component JavaScript →

Step 2:- Create Lightning Web Component : lwcVerticalNavigation.js

SFDX:Lightning Web Component >> New >> lwcVerticalNavigation.js

lwcVerticalNavigation.js [LWC JavaScript File]

  1.    import { LightningElement, track } from 'lwc';
  2.  
  3. export default class LwcVerticalNavigation extends LightningElement {
  4.  
  5.     @track currentContent = 'tutorial';
  6.     @track tutorialValue = false;    
  7.     @track integrationValue = false;
  8.     @track visualforceValue = false;
  9.     @track triggerValue = false;
  10.     @track jqueryJavascriptValue = false;
  11.     @track salesforceLwcValue = false;
  12.  
  13.  
  14.     changeHandleAction(event) {
  15.         const selected = event.detail.name;        
  16.  
  17.         this.currentContent = selected;
  18.  
  19.         if (selected == 'tutorial'){
  20.             this.tutorialValue = true;
  21.         }else{
  22.             this.tutorialValue = false;
  23.         }
  24.  
  25.         if (selected == 'integration'){
  26.             this.integrationValue = true;
  27.         }else{
  28.             this.integrationValue = false;
  29.         }
  30.  
  31.         if (selected == 'visualforce'){
  32.             this.visualforceValue = true;
  33.         }else{
  34.             this.visualforceValue = false;
  35.         }
  36.  
  37.         if (selected == 'trigger'){
  38.             this.triggerValue = true;
  39.         }else{
  40.             this.triggerValue = false;
  41.         }
  42.  
  43.         if (selected == 'jqueryJavascript'){
  44.             this.jqueryJavascriptValue = true;
  45.         }else{
  46.             this.jqueryJavascriptValue = false;
  47.         }
  48.  
  49.         if (selected == 'salesforceLwc'){
  50.             this.salesforceLwcValue = true;
  51.         }else{
  52.             this.salesforceLwcValue = false;
  53.         }
  54.  
  55.     }
  56. }

Create Lightning Web Component Meta XML →

Step 3:- Create Lightning Web Component : lwcVerticalNavigation.js-meta.xml

SFDX:Lightning Web Component >> New >> lwcVerticalNavigation.js-meta.xml

lwcVerticalNavigation.js-meta.xml [LWC Meta Data XML]

  1.    <?xml version="1.0" encoding="UTF-8"?>
  2. <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
  3.     <apiVersion>52.0</apiVersion>
  4.     <isExposed>true</isExposed>
  5.     <targets> 
  6.         <target>lightning__AppPage</target>
  7.         <target>lightning__RecordPage</target>
  8.         <target>lightning__HomePage</target>
  9.     </targets>
  10. </LightningComponentBundle>

Create Component Style CSS →

Step 4:- Create Lightning Web Component : lwcVerticalNavigation.css

SFDX:Lightning Web Component >> New >> lwcVerticalNavigation.css

lwcVerticalNavigation.css [Style CSS]

  1. .tabContent{display:block; padding:15px; font-size:14px; overflow: hidden; width: 70%;}
  2. .tabContent .postImage{display: inline-block; float:right; }
  3. .tabContent .postImage img{border:1px #ddd solid;}
  4. .readMore{font-size:14px; font-weight:bold; display:inline-block; padding:0 0 0 10px;}
  5. .readMore a{color:#ff0000; text-decoration:none;}
  6. .readMore a:hover{color:#04a5ca; text-decoration:underline;}
  7. .titleTag{font-size:18px;}
  8. .titleTag a{color:#003333; font-weight:bold;}
  9. .imgRt{width:52%; float:left;}

Create Lightning Application →

Step 5:- Create Lightning Application : lwcVerticalNavigationApp.app

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

lwcVerticalNavigationApp.app [Component Application File]

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

Further post that would you like to learn in Salesforce

 

 

 

FAQ (Frequently Asked Questions)

How do you navigate from one component to another in LWC?

To navigate from one Lightning Web Component to another Lightning Web Component, You need to add the target Lightning Web Component inside an Aura Component having lightning:isUrlAddressable is added as interface.

How do you navigate from LWC to LWC?

If you want to navigate the user from one LWC to another LWC, you can embed LWC in an Aura Component and navigate the user from LWC to an Aura Component.

How do you use lightning navigate?

In the client-side controller, set the pageReference attribute for the lightning component and set the state and attributes. Set the URL on your link using the generateUrl() method on the init handler. handleClick method on the button click will navigate to the Target component.

Related Topics | You May Also Like

  • Our Free Courses →
  • 👉 Get Free Course →

    📌 Salesforce Administrators

    📌 Salesforce Lightning Flow Builder

    📌 Salesforce Record Trigger Flow Builder

 
 


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