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

Avatar: Wrong className is getting used when image is undefined #4049

Closed
KOliver94 opened this issue Feb 14, 2023 · 1 comment · Fixed by #4053
Closed

Avatar: Wrong className is getting used when image is undefined #4049

KOliver94 opened this issue Feb 14, 2023 · 1 comment · Fixed by #4053
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@KOliver94
Copy link
Contributor

KOliver94 commented Feb 14, 2023

Describe the bug

Due to the changes in version 9.0.0 Avatar fallback is not working as intended because the wrong className is getting used.

I'm not sure what acutally changed between 8.7.3 and 9.0.0 but right now

if (props.image && !imageFailed) {
return <img src={props.image} alt={props.imageAlt} onError={onImageError}></img>;

props.image && !imageFailed will be false as undefined is a falsy value. This way the onImageError function will never be called and it will never set imageFailed to true. However
'p-avatar-image': props.image !== null && !imageFailed,

this line explicitly checks for null which will not catch undefined and as I said earlier imageFailed will never be set to true. So at the end we will use p-avatar-image which will create a transparent background.

Reproducer

CodeSandbox

PrimeReact version

9.0.0

React version

18.x

Language

TypeScript

Build / Runtime

Vite

Browser(s)

No response

Steps to reproduce the behavior

  1. Open attached CodeSandbox
  2. Switch primereact version from 9.0.0 to 8.7.3 to see the difference.

Expected behavior

Fallback icon Avatar should not have p-avatar-image in className and should not have transparent background.

@KOliver94 KOliver94 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 14, 2023
@KOliver94 KOliver94 changed the title Avatar: Fallback not working as intended Avatar: Wrong className is getting used when image is undefined Feb 14, 2023
@KOliver94 KOliver94 reopened this Feb 14, 2023
@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Feb 14, 2023
melloware added a commit to melloware/primereact that referenced this issue Feb 14, 2023
@melloware melloware added this to the 9.0.1 milestone Feb 14, 2023
@melloware melloware self-assigned this Feb 14, 2023
@melloware
Copy link
Member

Can you review my PR? Is there anything else that needs to be done?

@mertsincan mertsincan reopened this Feb 15, 2023
@github-actions github-actions bot added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 15, 2023
@melloware melloware removed the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 15, 2023
@melloware melloware modified the milestones: 9.1.0, 9.1.1, 9.1.2 Feb 15, 2023
mertsincan added a commit that referenced this issue Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants