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

Allow to set src and children in Avatar #17693

Closed
1 task done
lcswillems opened this issue Oct 3, 2019 · 2 comments · Fixed by #17694
Closed
1 task done

Allow to set src and children in Avatar #17693

lcswillems opened this issue Oct 3, 2019 · 2 comments · Fixed by #17694
Labels
good first issue Great for first contributions. Enable to learn the contribution process.

Comments

@lcswillems
Copy link
Contributor

lcswillems commented Oct 3, 2019

  • I have searched the issues of this repository and believe that this is not a duplicate.

Motivation 🔦

I would like to implement the avatar upload button in this Google Account page:

image

For this, the easiest solution (for me and for Google engineers) would be to put the upload button in the children and to show it over, i.e. to do something like this:

<Avatar src={myAvatarUrl}><UploadIcon /></Avatar>

But it doesn't work because when src is set, the children are not taken into account.

Summary

I propose to do a PR to replace the if/else at this position by:

children = childrenProp;

if (img) {
  children = (
    <>
      <img
        alt={alt}
        src={src}
        srcSet={srcSet}
        sizes={sizes}
        className={classes.img}
        {...imgProps}
      />
      {children}
    </>
  );
}
@oliviertassinari
Copy link
Member

@lcswillems The proposal sounds good to me. I don't see any harm in it.

@oliviertassinari oliviertassinari added component: avatar This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. and removed component: avatar This is the name of the generic UI component, not the React module! labels Oct 3, 2019
@lcswillems
Copy link
Contributor Author

Great! I have just submitted a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants