[Avatar] Handling image src with broken link
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:
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.
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 is your example actually working or is it a proposal? If it's the first one, we should definitly make it work.
@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.
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.
Is this still an active/open issue?
I feel like it would be valuable to have an example that show how to provide that onError callback, something simple.
A new iteration on this problem can found at #16161.