Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Avatar] Set background colour for AvatarGroup's borders #21700

Closed
WillSquire opened this issue Jul 7, 2020 · 5 comments · Fixed by #21896
Closed

[Avatar] Set background colour for AvatarGroup's borders #21700

WillSquire opened this issue Jul 7, 2020 · 5 comments · Fixed by #21896
Labels
component: avatar This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request

Comments

@WillSquire
Copy link
Contributor

WillSquire commented Jul 7, 2020

Summary 💡

Avatar group uses the background colour set for the app for the Avatar borders, but doesn't pick up on the background colour of the div it's within.

.MuiAvatarGroup-avatar {
  border-color: var(--background-color);
}

Examples 🌈

Solution could be to either have a property to set the border colour:

<AvatarGroup backgroundColor={something} />

or to wrap each one in a div that inherits the background colour from a parent. Giving a more hands-off approach.

Motivation 🔦

Used it on a different background and expected it to work without overriding colour.

@WillSquire WillSquire added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jul 7, 2020
@oliviertassinari
Copy link
Member

@WillSquire I have noticed that facebook.com uses a clip logic to solve this problem. However, I'm not sure about the added complexity. I don't see any clear solution out of this. The backgroundColor color sounds like an interesting tradeoff.

I have also noticed that the box model is wrong. We should change it:

diff --git a/packages/material-ui-lab/src/AvatarGroup/AvatarGroup.js b/packages/material-ui-lab/src/AvatarGroup/AvatarGroup.js
index 89ef01ac9..3716f65df 100644
--- a/packages/material-ui-lab/src/AvatarGroup/AvatarGroup.js
+++ b/packages/material-ui-lab/src/AvatarGroup/AvatarGroup.js
@@ -20,6 +20,7 @@ export const styles = (theme) => ({
   /* Styles applied to the avatar elements. */
   avatar: {
     border: `2px solid ${theme.palette.background.default}`,
+    boxSizing: 'content-box',
     marginLeft: -8,
     '&:last-child': {
       marginLeft: 0,

@oliviertassinari oliviertassinari added component: avatar This is the name of the generic UI component, not the React module! new feature New feature or request and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jul 7, 2020
@oliviertassinari oliviertassinari changed the title Set background colour for AvatarGroup's Avatar borders [Avatar] Set background colour for AvatarGroup's borders Jul 7, 2020
@WillSquire
Copy link
Contributor Author

WillSquire commented Jul 8, 2020

@oliviertassinari Thanks for getting back so fast. I'm racking my brains for a hands-off solution, but I think that could be clean for now. Would you like me to have a try with a pull request?

Also noticed border takes away from the avatar's default size (40px to 36px), but wasn't sure if this was by design? I bumped it to 44px and gave it a negative margin to make it flush with default Avatar when using it. content-box is much cleaner though :)

@oliviertassinari
Copy link
Member

I don't see any great solution for this:

  • inline-style: violate strict CSP
  • style function: too slow
  • SVG clip: feels over-engineered, hard to customize the shape
  • a custom class name: current tradeoff
  • else?

content-box is much cleaner though

Yeah, let's go with this.

@oliviertassinari oliviertassinari added the good first issue Great for first contributions. Enable to learn the contribution process. label Jul 10, 2020
@oliviertassinari
Copy link
Member

Adding the "good first issue" label so we fix the box-sizing: #21700 (comment).

Outside of this, I doubt we can improve the tradeoff, if not by making it easier to style the border color, which we plan in #15561.

natac13 added a commit to natac13/material-ui that referenced this issue Jul 23, 2020
@MrEbbinghaus
Copy link

Sorry to dig this up, after such a long time, but I noticed that the background/border color mismatch is very noticeable with the new paper colors in dark mode in v5.

Here is an example on an elevation12 paper:
image

On elevation1, it's still noticeable:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: avatar This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants