Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(platform): icon-tab-bar _generateTabBarItems function improvement #12581

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions libs/platform/icon-tab-bar/icon-tab-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,11 @@ export class IconTabBarComponent implements OnInit, TabList {
flatIndexRef = flatIndexRef || { value: 0 };
return config.map((item, index) => {
const uId = `${indexPrefix}${index}`;
if (!('color' in item)) {
item.color = 'default';
}
item.color = item.color || 'default';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you store item.color || 'default' in a variable instead of modifying the value directly?
For example: const color = item.color || 'default'
You can then use this variable in cssClasses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mutating item.color directly ensures that the item consistently has a valid color property in all cases inside return. By updating item.color early, it prevents potential future issues when item.color is referenced elsewhere in the result object or other parts of the code. Essentially, it is necessary for item.color to always have a valid value, but there is no better way to set it by default without similar mutation.

const result: IconTabBarItem = {
...item,
index,
cssClasses: [],
cssClasses: item.color ? [`fd-icon-tab-bar__item--${item.color}`] : [],
uId,
hidden: false,
parentUId,
Expand All @@ -371,9 +369,6 @@ export class IconTabBarComponent implements OnInit, TabList {
uId
)
};
if (item.color) {
result.cssClasses = [`fd-icon-tab-bar__item--${item.color}`];
}
return result;
});
}
Expand Down