Control tabs with WorkspaceAPI

Did you know you can use Workspace API in LWC?

With the Spring ‘24 release, Salesforce enabled the Workspace API in Lightning Web Components!

With the Spring ‘24 release, Salesforce enabled the Workspace API in Lightning Web Components!

What does it mean?

Control tabs with WorkspaceAPI — screenshot 1

Now you can control your application tabs - such as Home, shown above - within your LWC code. Learn more on the next page!

By using the Workspace API, you can, for example, close one of the tabs.

javascript
import { LightningElement, wire } from 'lwc';
import {
    IsConsoleNavigation,
    getFocusedTabInfo,
    closeTab
} from 'lightning/platformWorkspaceApi';

export default class TabController extends LightningElement {
    @wire(IsConsoleNavigation) isConsoleNavigation;

    closeHome() {
        if (this.isConsoleNavigation) {
            getFocusedTabInfo().then((tabInfo) => {
                closeTab(tabInfo.tabId);
            });
        }
    }
}

You can also focus, open new tab or refresh tab. Check link in post to learn more!

Text and code were extracted from the original slide. Plain-text version of the whole catalog