Skip to content

Fixed a runtime error caused by the Pills Container component trying to access an undefined icon. #3152

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

Merged
merged 9 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion components/pill-container/private/selected-listbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const getAvatar = (option) => {
};

const getIcon = (option) => {
const iconObject = option.icon;
const iconObject = option?.icon || null;
let icon = null;

if (iconObject) {
Expand Down
2 changes: 1 addition & 1 deletion components/pill/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class Pill extends React.Component {
};

renderIcon = () => {
const icon = this.props.icon || this.props.avatar;
const icon = this.props?.icon || this.props?.avatar;
Copy link
Contributor

@interactivellama interactivellama Sep 11, 2024

Choose a reason for hiding this comment

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

What is the situation that this.props becomes undefined within?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually the undefined problem is comming beacuse of selected-listbox.jsx getIcon funtion as In some cases option only have icon or in other case only avatar, there i have applied const iconObject = option?.icon || null; and here const icon = this.props?.icon || this.props?.avatar; for the extra safety.

if (icon) {
return <span className="slds-pill__icon_container">{icon}</span>;
}
Expand Down