Newer Version Available
focusTab() for Lightning Experience
Focuses 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 on which to focus. |
Sample Code
This component has a button that, when pressed, opens a new tab and focuses it.
Component code:
1<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
2 <lightning:workspaceAPI aura:id="workspace" />
3 <lightning:button label="Focus New Tab" onclick="{! c.focusNewTab }" />
4</aura:component>Controller code:
1({
2 focusNewTab : function(component, event, helper) {
3 var workspaceAPI = component.find("workspace");
4 workspaceAPI.openTab({
5 url: '/lightning/r/Account/001xx000003DI05AAG/view',
6 label: 'Global Media'
7 }).then(function(response) {
8 workspaceAPI.focusTab({tabId : response});
9 })
10 .catch(function(error) {
11 console.log(error);
12 });
13 }
14})Response
This method returns a promise that, upon success, resolves to true.