question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Menu to AvatarGroup when a max is set

See original GitHub issue

Feature request

Is your feature request related to a problem? Please describe.

I want to show a menu showing the rest of the users that exceed the max limit set on the AvatarGroup component

Example

Avatar group with menu

Describe the solution you’d like

We could add a way to wrap the remaining avatar label with a Menu component, maybe something like this

<AvatarGroup size="md" max={2}>
  <Avatar name="Ryan Florence" src="https://bit.ly/ryan-florence" />
  <Avatar name="Segun Adebayo" src="https://bit.ly/sage-adebayo" />
  <Avatar name="Kent Dodds" src="https://bit.ly/kent-c-dodds" />
  <Avatar name="Prosper Otemuyiwa" src="https://bit.ly/prosper-baba" />
  <Avatar name="Christian Nwamba" src="https://bit.ly/code-beast" />
  <Menu>
     <MenuButton>
      <AvatarGroup.Remaining/>
     </MenuButton>
     <MenuList>
        { /* ... */ }
     </MenuList>
  </Menu>
</AvatarGroup>

or add Menu inside AvatarGroup component and we pass a prop remainingMenuOption on how to render the remaining avatars in the menu list

<AvatarGroup 
size="md" 
max={2} 
remainingMenuOption={({name, src}) => 
<AvatarGroup.MenuOption>
  <Avatar name={name} src={src}/>
  <Text>{name}</Text>
</AvatarGroup.MenuOption>
}>
  <Avatar name="Ryan Florence" src="https://bit.ly/ryan-florence" />
  <Avatar name="Segun Adebayo" src="https://bit.ly/sage-adebayo" />
  <Avatar name="Kent Dodds" src="https://bit.ly/kent-c-dodds" />
  <Avatar name="Prosper Otemuyiwa" src="https://bit.ly/prosper-baba" />
  <Avatar name="Christian Nwamba" src="https://bit.ly/code-beast" />
</AvatarGroup>

these are rough ideas, I am not sure if spacing for the AvatarGroup would still work for the first example. I am also aware that AvatarGroup doesn’t take a list of users so am not sure how it will pass the name and src to remainingMenuOption.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
with-heartcommented, Dec 27, 2020

That’s an interesting use case. We’d need to add a context behind AvatarGroup and some additional components that allow you to use the excess avatars in some way. Not sure if that’s effort we’d be interested in spending, but I’ll reopen it as a feature so we can consider it.

2reactions
ljosberinncommented, Sep 15, 2020

Personally havent tried this yet but… what about:

<Menu as={AvatarGroup}>
  <MenuButton as={Avatar}>
    ...
  </MenuButton>
  <MenuList>
    <MenuItem as={Avatar}>...</MenuItem>
  </MenuList>
</Menu>

This should be solved through some kind of composition imo. Chakra aims to avoid this kind of app-individual implementation and tries to provide you with the tools you need to build it depending on your use-case. It seems to be more fitting for a guide post v1 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avatar - Chakra UI
Use the AvatarGroup component. To limit the amount of avatars to show, use the max prop. It'll truncate the avatars and show a...
Read more >
Avatar | Components | Vaadin Docs
When a name is set, Avatar auto-generates and display an ... You can specify the maximum number of items an Avatar Group should...
Read more >
How do I attach an event listener to the "max" Avatar in Mui's ...
It is possible to access the outerText of the event target, so in this case can add a check to the AvatarGroup onClick...
Read more >
Avatar Group - Avonni Components Documentation
Array of action objects. One action is displayed as a button icon. Two or more actions are displayed in a button menu.
Read more >
AvatarGroup API - Material UI - MUI
API reference docs for the React AvatarGroup component. ... You can override the existing props or add new ones. ... Max avatars to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found