+ Start a Discussion
Rima KACIRima KACI 

Aura Component/LWC openTab and positione focus

I've developped a screen searchResults Lightning web component which display liste of customers.
When I selected one customer and save it in salesforce(Account). I want to display it in tab and close searchResult screen.

To display created account, I've used NavigationMixin.Navigate
To close searchResult screen I've created Aura Component which contains my LWC to be able to use WorkspaceAPI and closeTab...

But when tab screen is closed the focus is positioned on the precedent tab not on created account tab.

How to positione focus on createdAccountTab?
thx for help

Code 

ParentAuraComponent.cmp

<aura:component implements="flexipage:availableForAllPageTypes" access="global">    
   
 <lightning:workspaceAPI aura:id="workspace"/> 
<div><c:searchClientCustomerByPhoneResults oncloseclicked="{!c.handleFilterChange}"/></div>    

</aura:component>



ParentAuraComonent.js

({
    handleFilterChange: function(component, event) {
var accountToDisplay = event.getParam('accountToDisplay');
var workspaceAPI = component.find("workspace"); 

workspaceAPI.getFocusedTabInfo().then(function(response) {
  
var focusedTabId = response.tabId;    
workspaceAPI.closeTab({tabId: focusedTabId});

 }).catch(function(error) { 
    console.log(error);

}
);


searchScreen.js(LWC)

saveRow() {

    saveAccountInSF({identifiant: this.identifiant}).then(result => {
                        
            if (result.length === 1) {  
                this.accountId = result[0].Id;                                                               
                /*Appel methode pour la consulation client */                                      
                this.navigateToRecordViewPage(); 
                closeTab();    
            } 
        }).catch(error => {
            this.error = error;                
        });
}        

        
closeTab(){
        var close = true;
        var accountToDisplay = this.accountId;
        //var urlToDisplay = this.url;
        const closeclickedevt = new CustomEvent('closeclicked', {
            detail: { close, accountToDisplay},
        });

         // Fire the custom event
        this.dispatchEvent(closeclickedevt);        
   }     
        
        
        
navigateToRecordViewPage() {
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.accountId,
                objectApiName: 'Account',
                actionName: 'view'
            }
        });
    }
Ramakrishna Reddy GouniRamakrishna Reddy Gouni
Use WorkspaceAPI to focus on required tab. Please check specifications and documentation of workspaceAPI.