Button Stateful

lightning:buttonStateful

A button that toggles between states.

For Aura components only. For LWC development, use lightning-button-stateful.

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline

A lightning:buttonStateful 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 states.

Use the variant and class attributes to apply additional styling.

The Lightning Design System utility icon category provides nearly 200 utility icons that can be used in lightning:button along with a text label. Although the Lightning Design System provides several categories of icons, only the utility category can be used with this component.

Visit https://lightningdesignsystem.com/icons/#utility to view the utility icons.

This component implements styling from stateful buttons in the Lightning Design System.

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 state to true, and deselecting it toggles the state to false. When the state is true, the button displays "Unfollow" when you mouse over it or when it receives focus.

The client-side controller toggles the state via the buttonstate attribute.

This component uses aria-live="polite", which means the button label is read after the current user task or content.

To inform screen readers that a button is disabled, set the disabled attribute to true.