Skip to content

Commit

Permalink
fix(avatar): Lazy load avatar images (#2833)
Browse files Browse the repository at this point in the history
Add `loading="lazy"` to the Avatar image element.

Fixes: #2832

[category:Components]
  • Loading branch information
NicholasBoll authored Jul 18, 2024
1 parent bea3e7c commit 714bc8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/react/avatar/lib/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export const Avatar: AvatarOverload = React.forwardRef(
onLoad={loadImage}
isLoaded={imageLoaded}
objectFit={objectFit}
loading="lazy"
/>
</StyledStack>
)}
Expand Down
10 changes: 10 additions & 0 deletions modules/react/avatar/stories/stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ storiesOf('Components/Indicators/Avatar', module)
<h3>Using a Square Image</h3>
<Avatar as="div" size={200} url="https://placekitten.com/g/450/450" />
</div>
))
.add('Lazy Loading', () => (
<div className="story">
{Array.from({length: 100}, (v, index) => (
<>
<Avatar as="div" size={Avatar.Size.xs} url={testAvatar + '?v=' + index} />
<br />
</>
))}
</div>
));

storiesOf('Components/Indicators/Avatar/Avatar Button', module)
Expand Down

0 comments on commit 714bc8e

Please sign in to comment.