[material-ui][AvatarGroup] Even with null results the avatar is still counted
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 99.1k
- Forks
- 32.5k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 106
Description
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Steps to reproduce 🕹
- Use the
AvatarGroupcomponent and loop an array of avatars inside. - Don't directly do the condition inside the
AvatarGroup, instead, render a child component and pass the current avatar data. - On the Child component, create a condition to either render the avatar or return null instead, so that the avatar won't be rendered.
Here is the Live Demo: SANDBOX-MATERIALUI-AVATAR-GROUP
Current behavior 😯
In some cases, I need to do the condition inside the child component to either render the avatar or not after fetching some data by using a hook which needs to be on the top level.
However, returning null to not render the avatar is still being counted by the avatargroup causing it to still render the + icon.
Expected behavior 🤔
Do not count the null avatars that are being returned so that the + icon will not be rendered.
Context 🔦
This makes the component look a bit buggy a it renders the + icon even without avatars. I'm not sure if this is a limitation in which we should not do it this way or if there is another approach we should be doing instead. Thank you!
Your environment 🌎
npx @mui/envinfo
Don't forget to mention which browser you used.
Output from `npx @mui/envinfo` goes here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the AvatarGroup implementation and the linked CodeSandbox demo at demo.tsx:57,44; inspect how child components that return null are counted. Done means null-rendering children are excluded from the count so the + indicator is absent when no visible avatars remain, with the behavior verified against the reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100