disableTabClose() for Lightning Experience

Prevents a workspace tab or subtab from closing. This method removes the close button from a tab or subtab, and disables the keyboard shortcuts that close tabs and subtabs. This method works only in Lightning console apps.

The method provides the same argument for both Aura Components and Lightning Web Components (LWC).

NameTypeDescription
tabIdstringThe ID of the workspace tab or subtab to disable tab close for.
disabledbooleanSpecifies whether to disable tab close.

disableTabClose() doesn’t prevent the browser from refreshing or closing the browser tab.

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.

This component has a button that, when pressed, disables the ability to close the currently focused tab.

Component code:

Controller code:

This method returns a promise that, upon success, resolves to a tabInfo object representing the focused 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.