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(avatar): Combine Avatar & AvatarButton and provide fallback image #614

Merged
merged 12 commits into from
May 14, 2020

Conversation

vibdev
Copy link
Contributor

@vibdev vibdev commented May 3, 2020

Summary

If the link for the avatar fails, eg 404 etc, we are currently showing a broken link. This could be made a bit nicer by rendering the default icon instead.

Not sure the best way to test this, should I just add an item to the storybook for avatar image?

Also open question if the icon should have a label with the altText passed in on failure?

Closes #613

BREAKING CHANGES

  • <AvatarButton> has been removed. By default <Avatar> will now be a button. If you need the old plain div version you can pass the prop as="div".

  • The component is now a functional component instead of a class. If you are using ref on the class version it will not be pointing to the same thing. buttonRef has changed to ref since it could now reference a button or a div

  • Visual change: Avatar images appear once they are load. While loading or if they fail to load the default icon will be shown. So you may want to check which variant you are using even in the image case.

Checklist

  • branch has been rebased on the latest master commit
  • tests are changed or added
  • yarn test passes
  • code has been documented and, if applicable, usage described in README.md
  • design approved final implementation
  • a11y approved final implementation
  • code adheres to the API & Pattern guidelines

Example

Avatar loading

@cypress
Copy link

cypress bot commented May 3, 2020



Test summary

343 0 1 0


Run details

Project canvas-kit
Status Passed
Commit 6856d42 ℹ️
Started May 14, 2020 5:17 AM
Ended May 14, 2020 5:21 AM
Duration 03:43 💡
OS Linux Ubuntu Linux - 18.04
Browser Electron 80

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@mannycarrera4 mannycarrera4 changed the title Provide a fallback if the avatar image fails to load, fixes #613 fix(avatar): Provide a fallback if the avatar image fails to load, fixes #613 May 4, 2020
@mannycarrera4 mannycarrera4 added the enhancement New feature or request label May 4, 2020
@NicholasBoll NicholasBoll linked an issue May 4, 2020 that may be closed by this pull request
@NicholasBoll
Copy link
Member

Overall, I like the idea. A few questions on the implementation to make it a better experience.

@vibdev
Copy link
Contributor Author

vibdev commented May 5, 2020

@anicholls @NicholasBoll Updated and unified as a single functional component, let me know what you think.

Copy link
Contributor

@anicholls anicholls left a comment

Choose a reason for hiding this comment

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

Can you rebase this onto prerelease/v4 and change the base branch as well?

Also, can you summarize the breaking changes in the PR description?

@anicholls anicholls added 4.x breaking-change A change that will break something for consumers labels May 6, 2020
@anicholls anicholls changed the title fix(avatar): Provide a fallback if the avatar image fails to load, fixes #613 fix(avatar): Provide a fallback if the avatar image fails to load May 6, 2020
@vibdev vibdev force-pushed the avatar-fallback branch from 6d8cfb9 to 8491dda Compare May 6, 2020 17:55
@vibdev vibdev changed the base branch from master to prerelease/v4 May 6, 2020 17:55
Co-authored-by: Alex Nicholls <anicholls3@gmail.com>
Copy link
Contributor

@anicholls anicholls left a comment

Choose a reason for hiding this comment

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

Looks great - thank you! 🎉

@anicholls anicholls changed the title fix(avatar): Provide a fallback if the avatar image fails to load fix(avatar): Combine Avatar & AvatarButton and provide fallback image May 11, 2020
/**
* The ref to the button or div that the styled component renders.
*/
ref?: React.Ref<HTMLButtonElement>;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this will work. Let me test it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered adding the ref in the Avatar overload but wasn't sure if it was needed since in Alex's example it wasn't split up.

Copy link
Member

Choose a reason for hiding this comment

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

I have confirmed this will not work and React will throw the following warning:

react.development.js:167 Warning: Avatar: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop.

I think ref is the correct prop, but we'll have to use forwardRef for the component to make that work. Some more details here: #548

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch 👍 We should make sure we have a test for this as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x breaking-change A change that will break something for consumers enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide fallback to icon when avatar image fails to load
4 participants