Fix avatar alt-text running into other elements on image load failure. (#38000)
This commit is contained in:
parent
1e5cad072e
commit
3c8e37907d
@ -26,6 +26,7 @@ exports[`<AvatarOverlay > renders a overlay avatar 1`] = `
|
|||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
alt="alice"
|
alt="alice"
|
||||||
|
onError={[Function]}
|
||||||
src="/static/alice.jpg"
|
src="/static/alice.jpg"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -44,6 +45,7 @@ exports[`<AvatarOverlay > renders a overlay avatar 1`] = `
|
|||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
alt="eve@blackhat.lair"
|
alt="eve@blackhat.lair"
|
||||||
|
onError={[Function]}
|
||||||
src="/static/eve.jpg"
|
src="/static/eve.jpg"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -10,6 +10,14 @@ interface Props {
|
|||||||
overlaySize?: number;
|
overlaySize?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleImgLoadError = (error: { currentTarget: HTMLElement }) => {
|
||||||
|
//
|
||||||
|
// When the img tag fails to load the image, set the img tag to display: none. This prevents the
|
||||||
|
// alt-text from overrunning the containing div.
|
||||||
|
//
|
||||||
|
error.currentTarget.style.display = 'none';
|
||||||
|
};
|
||||||
|
|
||||||
export const AvatarOverlay: React.FC<Props> = ({
|
export const AvatarOverlay: React.FC<Props> = ({
|
||||||
account,
|
account,
|
||||||
friend,
|
friend,
|
||||||
@ -38,7 +46,13 @@ export const AvatarOverlay: React.FC<Props> = ({
|
|||||||
className='account__avatar'
|
className='account__avatar'
|
||||||
style={{ width: `${baseSize}px`, height: `${baseSize}px` }}
|
style={{ width: `${baseSize}px`, height: `${baseSize}px` }}
|
||||||
>
|
>
|
||||||
{accountSrc && <img src={accountSrc} alt={account?.get('acct')} />}
|
{accountSrc && (
|
||||||
|
<img
|
||||||
|
src={accountSrc}
|
||||||
|
alt={account?.get('acct')}
|
||||||
|
onError={handleImgLoadError}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='account__avatar-overlay-overlay'>
|
<div className='account__avatar-overlay-overlay'>
|
||||||
@ -46,7 +60,13 @@ export const AvatarOverlay: React.FC<Props> = ({
|
|||||||
className='account__avatar'
|
className='account__avatar'
|
||||||
style={{ width: `${overlaySize}px`, height: `${overlaySize}px` }}
|
style={{ width: `${overlaySize}px`, height: `${overlaySize}px` }}
|
||||||
>
|
>
|
||||||
{friendSrc && <img src={friendSrc} alt={friend?.get('acct')} />}
|
{friendSrc && (
|
||||||
|
<img
|
||||||
|
src={friendSrc}
|
||||||
|
alt={friend?.get('acct')}
|
||||||
|
onError={handleImgLoadError}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user