Skip to content

Commit d1a33d8

Browse files
authored
[Avatar] Apply default background color for images (#7038)
Image avatars had the `styleOne` class applied by default giving them a jarring yellow background color. This change defaults to surface neutral to match our skeleton content. Before: ![image](https://screenshot.click/26-34-zf32m-1pr31.png) After: ![image](https://screenshot.click/26-34-zlwxl-c4hw5.png)
1 parent 69bfeec commit d1a33d8

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

.changeset/odd-plants-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': patch
3+
---
4+
5+
Applied default background color to image avatar

polaris-react/src/components/Avatar/Avatar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ export function Avatar({
102102
const className = classNames(
103103
styles.Avatar,
104104
size && styles[variationName('size', size)],
105-
!customer && styles[variationName('style', styleClass(nameString))],
106105
hasImage && status === Status.Loaded && styles.imageHasLoaded,
107106
shape && styles[variationName('shape', shape)],
107+
!customer &&
108+
!source &&
109+
styles[variationName('style', styleClass(nameString))],
108110
);
109111

110112
const imageClassName = classNames(

polaris-react/src/components/Avatar/tests/Avatar.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ describe('<Avatar />', () => {
3131
avatar.setProps({source: 'image/new/path'});
3232
}).not.toThrow();
3333
});
34+
35+
it('does not apply a style background class', () => {
36+
const src = 'image/path/';
37+
const avatar = mountWithApp(<Avatar source={src} />);
38+
expect(avatar).toContainReactComponent('span', {
39+
className: 'Avatar sizeMedium shapeRound',
40+
});
41+
expect(avatar).toContainReactComponent('span', {
42+
className: expect.not.stringContaining('styleOne'),
43+
});
44+
});
3445
});
3546

3647
describe('customer', () => {
@@ -44,6 +55,17 @@ describe('<Avatar />', () => {
4455
const avatar = mountWithApp(<Avatar customer source={src} />);
4556
expect(avatar).not.toContainReactComponent('svg');
4657
});
58+
59+
it('does not apply a style class', () => {
60+
const src = 'image/path/';
61+
const avatar = mountWithApp(<Avatar customer source={src} />);
62+
expect(avatar).toContainReactComponent('span', {
63+
className: 'Avatar sizeMedium shapeRound',
64+
});
65+
expect(avatar).toContainReactComponent('span', {
66+
className: expect.not.stringContaining('styleOne'),
67+
});
68+
});
4769
});
4870

4971
describe('Initials', () => {

0 commit comments

Comments
 (0)