I am working with an array of tabs and here is the code snippet:
const navTabs: ITab[] = [
{ Name: allTab, Icon: 'gs-all', Selected: true },
{ Name: sources.corporateResources, Icon: 'gs-resources', Selected: false },
{ Name: sources.employee, Icon: 'gs-people', Selected: false },
{ Name: sources.services, Icon: 'gs-services', Selected: false },
{ Name: sources.information, Icon: 'gs-docs', Selected: false },
{ Name: sources.tableau, Icon: 'gs-tableau', Selected: false },
];
In the method to activate a tab, I change the currently selected tab from selected: true
to false and then set the new tab to selected: true
.
Here is the activating code:
public activateTab(name: TabName): void {
this.activeTab = name;
this.navTabs.find(x => x.Selected === true).Selected = false;
this.navTabs.find(x => x.Name === name).Selected = true;
}
I'm wondering if there's a way to simplify this into a single operation. Is it possible?
this.navTabs.find(x => x.Selected === true).Selected = false;
this.navTabs.find(x => x.Name === name).Selected = true;