feat!: Revamped Avatar component#1048
Open
pawelgrimm wants to merge 37 commits into
Open
Conversation
a953da4 to
8f6ff49
Compare
doistbot
reviewed
May 27, 2026
Member
doistbot
left a comment
There was a problem hiding this comment.
Thanks pawelgrimm for your contribution 😊. The new fallback handling and dynamic image selection look solid, and the updated documentation featuring contributor avatars is a great touch.
Few things worth tightening:
- Wrap the component in
React.forwardRefand restore the...propsrest spread to the root element to maintain a flexible, standard API. - Derive the default fallback label from the normalized
nameinstead of the raw prop so whitespace-only inputs don't yield a blank accessible name. - Add a base
jest-axetest to the suite per our guidelines, alongside a targeted test verifying that customalttext is correctly exposed on the initials fallback.
I also included a few optional follow-up notes in the details below.
Optional follow-up notes (6)
- [P3] src/avatar/avatar.stories.tsx:9: This duplicates the supported-size list that already exists as
AVATAR_SIZESinutils.ts. If the component contract changes, the stories/playground can drift from the actual runtime/type surface. Import the shared constant here instead of maintaining a second copy. - [P3] src/avatar/utils.ts:74:
normalizeAvatarNamealready replaces all whitespace sequences with a single space. Using.split(' ')here produces identical results and avoids running the Unicode regex engine a second time. - [P3] src/avatar/utils.ts:147: Consider adding a fast-path
if (failedSources.length === 0) return imageProps;before checkingimageProps.sources. This avoids re-filtering the array and reconstructing the image properties object on every render for the typical happy path where no image sources have failed. - [P3] src/avatar/avatar.tsx:102:
getInitials(name)andgetAvatarMetaColorIndex(name)now run on every render, even whenavailableImageSourcesis truthy and the component never uses the initials/meta-color path. For image-heavy avatar lists, that adds avoidable normalization/segmentation/hash work to the hot path. Computing these only when we actually fall back to initials would avoid that per-render overhead. - [P3] src/avatar/avatar.mdx:25: This docs page now renders all of the image-heavy canvases inline, and most of those stories use live GitHub avatar URLs. Opening
Avatar.mdxwill trigger roughly 26 external image requests up front, which makes Storybook/Chromatic slower and less deterministic than it needs to be. Using local fixtures (or trimming the number of inline canvases) would avoid that resource overhead. - [P3] src/avatar/avatar.tsx:113: This new
metaColor-*class family is camel-cased, but Reactist’s CSS naming convention is dash-separated (variant-primary,size-small, etc.). Please rename these lookups/classes to something likemeta-color-*so Avatar stays consistent with the rest of the library.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
We are bringing the Avatar component up to spec with the design, including:
srcset)We also added a new documentation page for the component, which walks through all the features it supports. The new and improved stories feature all the contributors to this repo from the past year 😁
We also removed some features that we don't really need:
mediaquery-based responsive sizingname, if desired)Sorry for the rather large PR — I'd split it up, but that would mean pushing accompanying stories, docs, and tests in a separate PR, which isn't great either. Lmk if you feel strongly about having a smaller PR in this case and I can do my best to rework it.
References
Demo
📸 Demo
PR Checklist