How to create horizontal tabs uses of selected radio group button in Lightning Web Component – LWC | How to create radio group button functionality horizontal tabs uses of the “lightning-radio-group” selected value in LWC – Salesforce Lightning Web Component

2,703 views

Hey guys, today in this post we are going to learn about How to create Radio Group Button Functionality horizontal tabs uses of the “lightning-radio-group” selected value in LWC – Salesforce Lightning Web Component.

A lightning-radio-group component represents a group of radio buttons that permit only one button to be selected at a time. The component renders radio button “input” elements and assigns the same value to the name attribute for each element. The common name attribute joins the elements in a group. If you select any radio button in that group, any previously selected button in the group is deselected.

In general, we don’t recommend setting the name attribute in lightning-radio-group. The component automatically generates a unique value for name if none is provided. The generated value ensures a common name for the “input” elements rendered for the radio button group, and is unique in the page. To know more details about lightning-radio-group, Click Here →

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

 

 

Files we used to create Radio Group Button Functionality in LWC →

lwcCustomRadioButton.html LWC HTML File Template HTML file to create Radio Group Button Functionality in LWC
lwcCustomRadioButton.js LWC JavaScript File In the javascript file create handleRadioChange function in LWC
lwcCustomRadioButton.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.
lwcCustomRadioButtonApp.app Lightning Application It is used to call the component to preview on browser.

 

 

Final Output →

radio group button horizontal tabs 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 : lwcCustomRadioButton.html

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

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

lwcCustomRadioButton.html [Lightning Web Component HTML]

  1.    <template>
  2.     <lightning-card title="How can I get selected radio button value in Lightning Web Component -- LWC" icon-name="custom:custom19" size="small">
  3.     <div class="slds-p-around_medium">
  4.         <div class="slds-grid slds-wrap">
  5.             <div class="slds-col slds-size_12-of-12 slds-m-bottom--medium">
  6.  
  7.             <lightning-radio-group name="radioGroup"
  8.             label="Radio Group"
  9.             options={options}
  10.             value={value}
  11.             type="button"
  12.             onchange={handleRadioChange}>
  13.  
  14.             </lightning-radio-group>
  15.             </div>
  16.  
  17.             <div class="slds-col slds-size_12-of-12 slds-m-top--large">
  18.             <template if:true={salesforceLwcFieldValue}>               
  19.                 <h3 class="slds-text-heading_medium slds-text-color--error"><strong> Salesforce LWC</strong></h3> 
  20.                 <p>Enhance your Salesforce users’ experience with customizable Lightning Web Components. Find the Lightning Web Components that are right for you on AppExchange. Connect With Customers. Collaborate Better. Salesforce Admin Tools. To live demo project learn  <span class="readMore"><a href="https://www.w3web.net/tutorial/salesforce-lwc/" target="_blank" rel="noopener noreferrer">more...</a></span></p> 
  21.             </template> 
  22.  
  23.  
  24.             <template if:true={tutorialFieldValue}>
  25.                 <h3 class="slds-text-heading_medium slds-text-color--error"><strong>Tutorial</strong></h3> 
  26.                 <p>An easy way to learn step-by-step online salesforce free tutorial from <strong>w3web.net</strong>, To learn <span class="readMore"><a href="https://www.w3web.net/tutorial/" target="_blank" rel="noopener noreferrer">more...</a></span></p> 
  27.             </template> 
  28.  
  29.             <template if:true={techGuideFieldValue}>
  30.                 <h3 class="slds-text-heading_medium slds-text-color--error"><strong>Tech Guide</strong></h3> 
  31.                 <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. If you want to write a article English or Hindi very fast than go through the “Remote Mouse App”. <span class="readMore"><a href="https://www.w3web.net/technical-guide/" target="_blank" rel="noopener noreferrer">more...</a></span></p> 
  32.             </template> 
  33.  
  34.  
  35.                 <template if:true={blogFieldValue}>
  36.                     <h3 class="slds-text-heading_medium slds-text-color--error"><strong>Blog</strong></h3> 
  37.                     <p>How to start a blog and make money. Easy Guide Step-By-Step for Beginners follow given points. What is blog and how to start your blog? Blog is a platform where you can share your personal experience that you have in expertise. <span class="readMore"><a href="https://www.w3web.net/blog/" target="_blank" rel="noopener noreferrer">more...</a></span></p>
  38.  
  39.                 </template> 
  40.  
  41.             <template if:true={auraCompFieldValue}>               
  42.                 <h3 class="slds-text-heading_medium slds-text-color--error"><strong>Aura Component</strong></h3> 
  43.                 <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> 
  44.             </template> 
  45.  
  46.  
  47.             </div>
  48.         </div> 
  49.  
  50.  
  51.  
  52.         <br/><br/>
  53.     <!--StartRelatedTopics Section-->
  54. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  55.  
  56.         <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>
  57.  
  58.         <br/><br/>
  59.         <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>
  60.         <div style="display:block; overflow:hidden;"> 
  61.             <div style="width: 50%; float:left; display:inline-block">
  62.                 <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  63.                     <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>
  64.                     <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>
  65.                     <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>
  66.                     <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>
  67.                     <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>
  68.                 </ul>
  69.         </div>
  70.  
  71.         <div style="width: 50%; float:left; display:inline-block">
  72.                 <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  73.                     <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>
  74.                     <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>
  75.                     <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>
  76.                     <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>
  77.                     <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>
  78.                 </ul>
  79.             </div>
  80.            <div style="clear:both;"></div> 
  81.            <br/>
  82.             <div class="youtubeIcon">
  83.                 <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>
  84.             </div>
  85. </div>
  86.  
  87. </div>
  88.  
  89. <!--EndRelatedTopics Section-->
  90.  
  91.     </div>
  92.     <br/>
  93. <br/>
  94.  
  95. </lightning-card>
  96. </template>

 

Create Lightning Web Component JavaScript →

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

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

lwcCustomRadioButton.js [LWC JavaScript File]

  1.    import { LightningElement, track } from 'lwc';
  2.  
  3. export default class LwcCustomRadioButton extends LightningElement {
  4.     value = 'Salesforce LWC';
  5.  
  6.     get options() {
  7.         return [
  8.             { label: 'Salesforce LWC', value: 'Salesforce LWC' },
  9.             { label: 'Tutorial', value: 'Tutorial' },
  10.             { label: 'Tech Guide', value: 'Tech Guide' },
  11.             { label: 'Blog', value: 'Blog' },
  12.             { label: 'Aura Component', value: 'Aura Component' },
  13.  
  14.         ];
  15.     }
  16.     @track salesforceLwcFieldValue = true;
  17.     @track tutorialFieldValue = false;
  18.     @track techGuideFieldValue = false;
  19.     @track blogFieldValue = false; 
  20.     @track auraCompFieldValue = false;
  21.  
  22.  
  23.     handleRadioChange(event) {
  24.         const selectedOption = event.detail.value;
  25.         //alert('selectedOption ' + selectedOption);
  26.         if (selectedOption == 'Salesforce LWC'){
  27.             this.salesforceLwcFieldValue = true;
  28.         }
  29.         else{
  30.             this.salesforceLwcFieldValue = false;
  31.         }
  32.  
  33.         if (selectedOption == 'Tutorial'){
  34.             this.tutorialFieldValue = true;
  35.         }else{
  36.             this.tutorialFieldValue = false;
  37.         }
  38.  
  39.  
  40.         if (selectedOption == 'Tech Guide'){
  41.             this.techGuideFieldValue = true;
  42.         }else{
  43.             this.techGuideFieldValue = false;
  44.         }
  45.  
  46.         if (selectedOption == 'Blog'){
  47.             this.blogFieldValue = true;
  48.         }else{
  49.             this.blogFieldValue = false;
  50.         }
  51.  
  52.  
  53.       if (selectedOption == 'Aura Component'){
  54.             this.auraCompFieldValue = true;
  55.         }
  56.         else{
  57.             this.auraCompFieldValue = false;
  58.         }
  59.  
  60.     }
  61. }

 

Create Lightning Web Component Meta XML →

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

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

lwcCustomRadioButton.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 4:- Create Lightning Application : lwcCustomRadioButtonApp.app

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

lwcCustomRadioButtonApp.app [Component Application File]

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

 

radio group button horizontal tabs in lwc -- w3web.net
 

Further post that would you like to learn in Salesforce

 

 

FAQ (Frequently Asked Questions)

Can radio buttons be horizontal?

To make a horizontal radio button set, add the data-type='horizontal' to the fieldset . The framework will float the labels so they sit side-by-side on a line, hide the radio button icons and only round the left and right edges of the group.

How do you show radio buttons horizontally in lightning?

Currently in lightning component there is no direct way to display a lightning:radiobuttongroup horizontally. However, we have style class named slds-form-element__control and slds-radio which can perform this.

How do you add radio buttons in LWC?

Custom radio buttons are created by applying the . slds-radio class to a 'label' element. To remain accessible to all user agents, place an 'input' with type='radio' inside the 'label' element.

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