change stateful button value in lwc -- w3web.net

How to change the state of button value as ‘follow/unfollow’ or ‘like/dislike’ through onclick handler method uses of ‘lightning-button-stateful’ tag elements in Salesforce LWC (Lightning Web Component) | How to change the state of lightning:buttonStateful label value as ‘like/dislike’ or ‘following/unfollowing’ use an onclick handler method in Lightning Web Component – LWC (Salesforce)

1,201 views

Hey guys, today in this post we are going to learn about How to change the state of button value as ‘follow/unfollow’ or ‘like/dislike’ through onclick handler method uses of ‘lightning-button-stateful’ tag elements in Salesforce LWC (Lightning Web Component).

A lightning-button-stateful component represents a button that toggles between states, similar to a Like button on social media. Stateful buttons can show a different label and icon based on their selected states.

To handle the state change when the button is clicked, use the onclick event handler. This example enables you to toggle the button between states, displaying the “Follow” label by default, and replacing it with “Following” when the button is selected. Selecting the button toggles the selected state to true, and deselecting it toggles selected state to false. When the selected state is true, the button displays “Unfollow” when you mouse over it or when it receives focus. To know more details about lightning-button-stateful, Click Here.

 

Files we used to create lightning-button-stateful as ‘follow/unfollow’ Or ‘like/dislike’ in Salesforce LWC →

lwcButtonStateful.html LWc HTML File Template HTML file to create lightning-button-stateful as ‘follow/unfollow’ Or ‘like/dislike’ in Salesforce Lightning Web Component (LWC)
lwcButtonStateful.js LWC JavaScript File It’s javascript actions functions to ‘like/dislike’ or toggle the ‘lightning-button-stateful’ in Salesforce LWC
lwcButtonStateful.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.
lwcButtonStatefulApp.app Lightning Application It is used for call the component and preview on browser.

 

 

Final Output →

change stateful button value in lwc -- w3web.net

 

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 : lwcButtonStateful.html

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

lwcButtonStateful.html [Lightning Web Component HTML]

 

Create Lightning Web Component JavaScript →

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

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

lwcButtonStateful.js [LWC JavaScript File]

 

Create Lightning Web Component Meta XML →

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

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

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

 

Create Lightning Application →

Step 4:- Create Lightning Application : lwcButtonStatefulApp.app

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

lwcButtonStatefulApp.app [Component Application File]

 
change stateful button value in lwc -- w3web.net
 

Further post that would you like to learn in Salesforce

 

 

FAQ (Frequently Asked Questions)

What is stateful button?

The stateful button is a button used to display an actionable icon. The stateful button doesn't share all the properties of the standard button component. The stateful button only displays an icon and cannot display any other elements, like labels. The button can be toggled between an on and off state.

How do you make a responsive lightning button?

The first step in creating a responsive layout is to implement a fluid grid. The SLDS grid utility provides a mobile-first layout system with granular column control. To implement the grid system in a Lightning web component, use the lightning-layout and lightning-layout-item base components.

How do you disable the Lightning button after clicking?

For Disabling a button you can create an boolean attribute in the component and use this attribute in the disabled attribute of button tag. Whenever you want to disable the button in the click you can make the attribute to true,so that the button will be disabled.

Related Topics | You May Also Like

  • Your reaction of the article ▾
 

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

2 thoughts on “How to change the state of button value as ‘follow/unfollow’ or ‘like/dislike’ through onclick handler method uses of ‘lightning-button-stateful’ tag elements in Salesforce LWC (Lightning Web Component) | How to change the state of lightning:buttonStateful label value as ‘like/dislike’ or ‘following/unfollowing’ use an onclick handler method in Lightning Web Component – LWC (Salesforce)”

Leave a Comment