Newer Version Available

This content describes an older version of this product. View Latest

closeTab() for Lightning Experience

Closes a workspace tab or subtab. This method works only in Lightning console apps.

Arguments

Name Type Description
tabId string ID of the workspace tab or subtab to close.

Sample Code

This component has a button that, when pressed, closes the currently focused tab.

Component code:

1<aura:component implements="flexipage:availableForAllPageTypes" access="global">
2    <lightning:workspaceAPI aura:id="workspace"/>
3    <lightning:button label="Close Focused Tab" onclick="{!c.closeFocusedTab}"/>
4</aura:component>

Controller code:

1({
2    closeFocusedTab : function(component, event, helper) {
3        var workspaceAPI = component.find("workspace");
4        workspaceAPI.getFocusedTabInfo().then(function(response) {
5            var focusedTabId = response.tabId;
6            workspaceAPI.closeTab({tabId: focusedTabId});
7        })
8        .catch(function(error) {
9            console.log(error);
10        });
11    }
12})

Response

This method returns a promise that, upon success, resolves to true.