setTabIcon() for Lightning Experience
Sets the icon and alternative text of the specified tab. This method works only in Lightning console apps.
| Name | Type | Description |
|---|---|---|
tabId | string | The ID of the tab for which to set the icon. |
icon | string | An SLDS icon key in the format utility:iconName where utility is the icon category. See a full list of utility icons on the SLDS reference site. |
iconAlt | string | Optional. Alternative text for the icon. |
This component has a function that sets an icon on a specified tab. It uses the tabId property from getFocusedTabInfo().
For another example that uses setTabIcon(), see the workspaceAPISetTabIcon component in the lwc-recipes repo.
To make your component available for use in a Lightning console app, specify the lightning__AppPage target in the component’s configuration file.
This component has a button that, when pressed, sets the icon of the focused tab to the SLDS “Approval” action icon.
Component code:
Controller code:
This method returns a promise that, upon success, resolves to a tabInfo object representing the modified tab. A tabInfo object is a JSON array of information about a workspace tab, with nested arrays of information on each subtab. This is the structure of a tabInfo object.