Newer Version Available
disableTabClose() for Lightning Experience
Arguments
The method provides the same argument for both Aura Components and Lightning Web Components (LWC).
| Name | Type | Description |
|---|---|---|
| tabId | string | The ID of the workspace tab or subtab to disable tab close for. |
| disabled | boolean | Specifies whether to disable tab close. |
LWC Sample Code
This component has a function that opens a tab using a page reference and then prevents it from being closed. When the openTab() method resolves successfully, it returns the tabInfo object. The const { tabId } syntax destructures the tabInfo object and binds the tabInfo.tabId value on the tabId variable. disableTabClose() uses this tabId value to prevent the tab from closing.
For another example that uses disableTabClose(), see the workspaceAPIDisableTabClose 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.
Aura Components Sample Code
This component has a button that, when pressed, disables the ability to close the currently focused tab.
Component code:
Controller code: