Create Button Menu with Custom dropdown with a list of actions/functions and display selected value when you click on list option uses of ‘lightning-button-menu’ tag element in Salesforce lightning web component – LWC | Set the value of ‘lightning-button-menu’ drop-down menu button and show/hide the content’s on-selected link of list option in Salesforce LWC – Lightning Web Component (Salesforce)

5,961 views


Hey guys, today in this post we are going to learn about Create Button Menu with Custom dropdown with a list of actions/functions and display selected value when you click on list option uses of ‘lightning-button-menu’ tag element in Salesforce lightning web component – LWC.

A lightning-button-menu component represents a button that displays a dropdown menu of actions or functions when you click it.

The menu closes when you click away from it, and it also closes and puts the focus back on the button when you select a menu item.

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
   

Use lightning-menu-item components nested in lightning-button-menu to specify the menu items for the button menu. To know more details about lightning-button-menu, Click Here.

 

 

Files we used to Button Menu with Custom Dropdown in Salesforce LWC →

buttonMenuLwc LWc HTML File Template HTML file to Button Menu with Custom dropdown in Salesforce Lightning Web Component (LWC)
buttonMenuLwc.js LWC JavaScript File It’s hold the list of actions/functions and display selected value when you click in Salesforce LWC..
buttonMenuLwc.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.
buttonMenuLwcApp.app Lightning Application It is used for call the component and preview on browser.

Final Output →

dropdown with lightning button menu in lwc -- 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 : buttonMenuLwc.html

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 

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

buttonMenuLwc.html [Lightning Web Component HTML]

  1.   <template>
  2. <lightning-card>
  3.     <div class="slds-m-around_medium" style="width:70%;"> 
  4.         <h3 class="slds-text-heading_medium"><lightning-icon icon-name="custom:custom88" size="small"></lightning-icon> <strong style="color:#270086; font-size:13px; margin-right:5px;"> Create Button Menu with Custom OnSelect Behavior in Lightning Web Component (LWC) </strong></h3>
  5.         <br/>
  6.  
  7. <div class="slds-m-top_medium slds-m-bottom_x-large">
  8.  
  9.     <div class="slds-p-around_medium lgc-bg">
  10.         <lightning-button-menu alternative-text="Show menu" variant="border-filled" onselect={handleOnselect}>
  11.             <lightning-menu-item value="integration" label="Integration"></lightning-menu-item>
  12.             <lightning-menu-item value="salesforceLWC" label="Salesforce LWC"></lightning-menu-item>
  13.             <lightning-menu-item value="auraComponent" label="Aura Component"></lightning-menu-item>
  14.             <lightning-menu-item value="salesforceTrigger" label="Salesforce Trigger"></lightning-menu-item>            
  15.         </lightning-button-menu>
  16.  
  17.         <span style=" display:inline-block; margin-left:10px;">The value of the menu item you <strong> Selected is:- </strong> <span class="slds-text-heading_small" style="color:#ff0000; font-weight:bold;">{selectedItemValue} →</span></span>
  18.     </div>
  19.  
  20.  
  21.     <div class="slds-col slds-size_10-of-12">
  22.         <template if:true={integrationVal}>
  23.             <h3 class="slds-text-heading_medium slds-text-color--error"><strong><a href="https://www.w3web.net/aws-s3-integration-step-by-step-in-salesforce/" target="_blank" rel="noopener noreferrer">Salesforce IntegrationVal</a></strong></h3> 
  24.             <p>How to Integrate Amazon S3 into Salesforce Uses of Named Credentials and checked the results Status=OK, StatusCode=200 after connected Amazon AWS S3 through the anonymous window in Salesforce | Integrate aws s3 using named credentials in Salesforce. <span class="readMore"><a href="https://www.w3web.net/aws-s3-integration-step-by-step-in-salesforce/" target="_blank" rel="noopener noreferrer">more...</a></span></p>
  25.  
  26.         </template>
  27.  
  28.  
  29.         <template if:true={salesforceLWCVal}>
  30.             <h3 class="slds-text-heading_medium slds-text-color--error"><strong><a href="https://www.w3web.net/lwc-fetch-picklist-values-without-apex-in-salesforce/" target="_blank" rel="noopener noreferrer">Salesforce LWC</a></strong></h3> 
  31.             <p>Retrieve picklist values dynamically of Opportunity Object without apex class using ‘uiObjectInfoApi’ property and displaying the selected pick-list value in Salesforce Lightning Component — LWC. <span class="readMore"><a href="https://www.w3web.net/lwc-fetch-picklist-values-without-apex-in-salesforce/" target="_blank" rel="noopener noreferrer">more...</a></span></p>
  32.  
  33.         </template>
  34.  
  35.  
  36.         <template if:true={auraComponentVal}>
  37.             <h3 class="slds-text-heading_medium slds-text-color--error"><strong><a href="https://www.w3web.net/tutorial/lightning-component/" target="_blank" rel="noopener noreferrer">Aura Component</a></strong></h3> 
  38.             <p>The Lightning Component framework is a UI framework for developing web apps for mobile and desktop devices. It's a modern framework for building single-page applications with dynamic, responsive user interfaces for Lightning Platform apps. To live demo project learn  <span class="readMore"><a href="https://www.w3web.net/tutorial/lightning-component/" target="_blank" rel="noopener noreferrer">more...</a></span></p> 
  39.  
  40.         </template>
  41.  
  42.         <template if:true={salesforceTriggerVal}>
  43.             <h3 class="slds-text-heading_medium slds-text-color--error"><strong><a href="https://www.w3web.net/trigger-to-update-account-phone-with-contact-phone/" target="_blank" rel="noopener noreferrer">Salesforce Trigger</a></strong></h3> 
  44.             <p> today in this post we are going to learn about How to Write a trigger to update parent account phone number when ever the contact phone number is updated using trigger handler and helper class in Salesforce.</p> 
  45.             <p><strong>Real time scenarios:-</strong> Write a trigger on Contact to update the parent Account Phone number when ever the Contact Phone is updated through trigger handler and helper class in Salesforce. <span class="readMore"><a href="https://www.w3web.net/trigger-to-update-account-phone-with-contact-phone/" target="_blank" rel="noopener noreferrer">more...</a></span></p>    
  46.         </template>
  47.  
  48.   </div>
  49.  
  50.   <br/><br/>
  51.   <!--Start RelatedTopics Section-->
  52. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  53.  
  54.       <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>
  55.  
  56.       <br/><br/>
  57.       <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>
  58.       <div style="display:block; overflow:hidden;"> 
  59.           <div style="width: 50%; float:left; display:inline-block">
  60.               <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  61.                   <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>
  62.                   <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>
  63.                   <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>
  64.                   <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>
  65.                   <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>
  66.               </ul>
  67.       </div>
  68.  
  69.       <div style="width: 50%; float:left; display:inline-block">
  70.               <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  71.                   <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>
  72.                   <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>
  73.                   <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>
  74.                   <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>
  75.                   <li><a href="https://www.w3web.net/tree-grid-dynamic-expand-collapse-in-lwc/" target="_blank" rel="noopener noreferrer">how to create tree grid with expanded/collapsed section for the entire row in LWC</a></li>
  76.               </ul>
  77.           </div>
  78.          <div style="clear:both;"></div> 
  79.          <br/>
  80.           <div class="youtubeIcon">
  81.               <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>
  82.           </div>
  83. </div>
  84.  
  85. </div>
  86.  
  87. <!--End RelatedTopics Section-->
  88.  
  89. </div>
  90. </div>
  91. </lightning-card>
  92. </template>

Create Lightning Web Component JavaScript →

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

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

buttonMenuLwc.js [LWC JavaScript File]

  1.   import { LightningElement,track } from 'lwc';
  2.  
  3. export default class ButtonMenuLwc extends LightningElement {
  4.     @track integrationVal = false;
  5.     @track salesforceLWCVal = false;
  6.     @track auraComponentVal = false;
  7.     @track salesforceTriggerVal = false;
  8.  
  9.     selectedItemValue;
  10.  
  11.     handleOnselect(event) {
  12.         this.selectedItemValue = event.detail.value;
  13.  
  14.         if (this.selectedItemValue == 'integration'){
  15.             this.integrationVal = true;
  16.         }else{
  17.             this.integrationVal = false;
  18.         }
  19.  
  20.         if (this.selectedItemValue == 'salesforceLWC'){
  21.             this.salesforceLWCVal = true;
  22.         }else{
  23.             this.salesforceLWCVal = false;
  24.         }
  25.  
  26.         if (this.selectedItemValue == 'auraComponent'){
  27.             this.auraComponentVal = true;
  28.         }else{
  29.             this.auraComponentVal = false;
  30.         }
  31.         if (this.selectedItemValue == 'salesforceTrigger'){
  32.             this.salesforceTriggerVal = true;
  33.         }else{
  34.             this.salesforceTriggerVal = false;
  35.         }
  36.  
  37.     }
  38.  
  39. }

Create Component Style CSS →

Step 3:- Create Lightning Web Component : buttonMenuLwc.css

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

buttonMenuLwc.css [Style CSS]

  1.   .lgc-bg {
  2.     background-color: rgb(242, 242, 242);
  3. }
  4.  
  5. .lgc-bg-inverse {
  6.     background-color: rgb(22, 50, 92);
  7. }

Create Lightning Web Component Meta XML →

Step 4:- Create Lightning Web Component : buttonMenuLwc.js-meta.xml

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

buttonMenuLwc.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>45.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 Lightning Application →

Step 5:- Create Lightning Application : buttonMenuLwcApp.app

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

buttonMenuLwcApp.app [Component Application File]

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

 
dropdown with lightning button menu in lwc -- w3web.net
 

Further post that would you like to learn in Salesforce

 

 

FAQ (Frequently Asked Questions)

What is a lightning button?

A lightning:button component represents a button element that executes an action in a controller. Clicking the button triggers the client-side controller method set for on click. Buttons can be either a label only, label and icon, body only, or body and icon.

What is variant in lightning button?

Base component variants correspond to blueprint variations in Lightning Design System. Variants change the appearance of a component and are controlled by the variant attribute.

Which method finds ID of components?

To find the local ID for a component in JavaScript, use cmp. getLocalId().

Related Topics | You May Also Like

 
Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 
  

Our Free Courses →

👉 Get Free Course →

📌 Salesforce Administrators

📌 Salesforce Lightning Flow Builder

📌 Salesforce Record Trigger Flow Builder

👉 Get Free Course →

📌 Aura Lightning Framework

📌 Lightning Web Component (LWC)

📌 Rest APIs Integration



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