Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
EnclosingTabId Context Wire Adapter for Lightning Experience
To determine if the component is within a tab or subtab, use this context wire adapter. If a caller component isn’t using the wire adapter inside a tab or subtab, the enclosing utility tab ID is null.
LWC Sample Code
To get the ID of the enclosing tab in LWC, use the EnclosingTabId wire adapter.
This component retrieves the enclosing tab ID and closes the tab.
1import { LightningElement, wire } from 'lwc';
2import { EnclosingTabId, closeTab } from 'lightning/platformWorkspaceApi';
3
4export class CloseEnclosingTabExample extends LightningElement {
5 @wire(EnclosingTabId) enclosingTabId;
6
7 handleClick() {
8 // Ensure that we have a tab open
9 if (!this.enclosingTabId) {
10 return;
11 }
12 closeTab(this.enclosingTabId);
13 }
14}For another example that uses the EnclosingTabId wire adapter, see openSubtab().
To make your component available for use in a Lightning console app, specify the lightning__AppPage target in the component’s configuration file.
Response
This method returns a promise that, upon success, resolves to the tabId of the enclosing tab, if within a tab. If not within a tab, this method resolves to false upon success.