From 136e9a9b8d2d19ca6294136aeae8be6bb4ffad09 Mon Sep 17 00:00:00 2001 From: Sugan G Date: Thu, 2 Nov 2023 15:05:53 +0530 Subject: [PATCH] [terra-tabs] Fixes tab label update (#1868) Co-authored-by: Sugan G --- packages/terra-tabs/CHANGELOG.md | 4 ++++ packages/terra-tabs/src/common-tabs/_Tabs.jsx | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/terra-tabs/CHANGELOG.md b/packages/terra-tabs/CHANGELOG.md index 8b2dbd89406..e3eaadb54f2 100644 --- a/packages/terra-tabs/CHANGELOG.md +++ b/packages/terra-tabs/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +* Fixed + * Fixes issue where tab label fails to get updated due to + having the same key before and after tab label update. + ## 7.11.1 - (October 25, 2023) * Fixed diff --git a/packages/terra-tabs/src/common-tabs/_Tabs.jsx b/packages/terra-tabs/src/common-tabs/_Tabs.jsx index 06796d28a40..0b63721df90 100644 --- a/packages/terra-tabs/src/common-tabs/_Tabs.jsx +++ b/packages/terra-tabs/src/common-tabs/_Tabs.jsx @@ -159,12 +159,16 @@ class Tabs extends React.Component { const prevTab = prevProps.tabData.find((tab) => tab.isSelected === true); const currTab = this.props.tabData.find((tab) => tab.isSelected === true); const prevtabKeys = []; + const prevtabLabels = []; prevProps.tabData.forEach(child => { prevtabKeys.push(child.id); + prevtabLabels.push(child.label); }); const curtabKeys = []; + const curtabLabels = []; this.props.tabData.forEach(child => { curtabKeys.push(child.id); + curtabLabels.push(child.label); }); // Allow dynamic addition of tabs. @@ -175,8 +179,10 @@ class Tabs extends React.Component { let isTabEqual = false; for (let i = 0; i < curtabKeys.length; i += 1) { const prevKey = prevtabKeys[i]; + const prevLabel = prevtabLabels[i]; const curKey = curtabKeys[i]; - if (prevKey !== curKey) { + const curLabel = curtabLabels[i]; + if (prevKey !== curKey || prevLabel !== curLabel) { isTabEqual = true; } }