material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[Avatar] Handling image src with broken link

Open shin-monkey opened this issue 10 years ago • 8 comments

Problem description

Is there any way to handle broken img src link inside avatar? Some sort of "onError" tag.

Steps to reproduce

Just put a broken img link inside

Versions

  • Material-UI:
  • React:
  • Browser:

shin-monkey avatar Sep 26 '16 23:09 shin-monkey

We don't provide any way to handle broken image source for the Avatar component. That sounds like a broader issue. That would make sense to create a side project to handle this problem. I'm closing this issue as I don't think that we should provide it here. If you find something relevant. We could add it to the documentation.

oliviertassinari avatar Sep 27 '16 11:09 oliviertassinari

Doing with a simple I use like that:

<img src={record.picture} onError={(e)=>{e.target.src="http://mydomain.com/img/user_null.png"}}/>

If material-ui would provide a error callback loading the src parameter, would be great.

TiagoGouvea avatar Oct 14 '16 12:10 TiagoGouvea

@TiagoGouvea is your example actually working or is it a proposal? If it's the first one, we should definitly make it work.

oliviertassinari avatar Oct 14 '16 17:10 oliviertassinari

@oliviertassinari my exemple work fine to img objects. I think can be easy to put it on avatar, where, some times, we don't have the person picture anymore, or the image are stored on a third party server.

TiagoGouvea avatar Oct 18 '16 08:10 TiagoGouvea

I have created a reproduction test case to illustrate https://jsfiddle.net/69z2wepo/65368/. On the next branch, you should be able to provide a onError callback property.

oliviertassinari avatar Dec 18 '16 21:12 oliviertassinari

Is this still an active/open issue?

sajal50 avatar Jun 08 '17 07:06 sajal50

I feel like it would be valuable to have an example that show how to provide that onError callback, something simple.

oliviertassinari avatar Jun 08 '17 07:06 oliviertassinari

A new iteration on this problem can found at #16161.

oliviertassinari avatar Dec 06 '19 18:12 oliviertassinari