UNPKG

@limetech/lime-elements

Version:
19 lines (18 loc) 739 B
/** * Set a tabs `active` state to true in a list of tabs. The previous tab with * `active` set to true will have it set to `false` instead. * * @param tabs - list of tabs * @param index - the index of the tab to set to active * @returns a copy of the list of tabs with the changed tabs replaced */ export function setActiveTab(tabs, index) { const oldSelectedTabIndex = tabs.findIndex((t) => t.active === true); const result = [...tabs]; if (oldSelectedTabIndex !== -1) { result[oldSelectedTabIndex] = Object.assign(Object.assign({}, tabs[oldSelectedTabIndex]), { active: false }); } result[index] = Object.assign(Object.assign({}, tabs[index]), { active: true }); return result; } //# sourceMappingURL=tabs.js.map