Skip to content

Commit 716956d

Browse files
QuintonCkyledurand
andauthored
Avatar - Bugfix shape styling (#7022)
<!-- ☝️How to write a good PR title: - Prefix it with [ComponentName] (if applicable), for example: [Button] - Start with a verb, for example: Add, Delete, Improve, Fix… - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ### WHY are these changes introduced? Fixes #7021 <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing? This resolves an issue that is present with square Avatar components. The issue is that the Avatar and Image classes were defaulting to the rounded border-radius rather than the expected border radius given the shape. The `shape{Round || Square}` class instead sets the `border-radius` value and the Avatar and Image classes inherit the border-radius from their parent component. | Before | After | | - | - | | <img width="330" alt="Screen Shot 2022-08-25 at 11 31 02 AM" src="https://user-images.githubusercontent.com/4250423/186721070-6e098933-062e-4295-b52d-774bb4a906c1.png"> | <img width="418" alt="Screen Shot 2022-08-25 at 11 31 34 AM" src="https://user-images.githubusercontent.com/4250423/186721072-b1559e34-cb37-48f7-8ebb-e37353e814ca.png"> | <!-- Summary of the changes committed. Before / after screenshots are appreciated for UI changes. Make sure to include alt text that describes the screenshot. If you include an animated gif showing your change, wrapping it in a details tag is recommended. Gifs usually autoplay, which can cause accessibility issues for people reviewing your PR: <details> <summary>Summary of your gif(s)</summary> <img src="..." alt="Description of what the gif shows"> </details> --> <!-- ℹ️ Delete the following for small / trivial changes --> ### How to 🎩 Visit Storybook and look at the Square component with an external URL. ### 🎩 checklist - [ ] ~Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing)~ - Not entirely sure this is necessary since this is a simple CSS regression. If you feel strongly against this decision I'm not opposed to including testing on mobile devices. I've tested with Chrome, Firefox, and Safari. Edge is built on Chromium 🤷 - [x] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [ ] ~Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)~ N/A - [ ] ~Updated the component's `README.md` with documentation changes~ N/A - [ ] ~[Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide~ N/A Co-authored-by: Kyle Durand <kyledurand@users.noreply.github.com>
1 parent a8087a3 commit 716956d

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

.changeset/breezy-years-sing.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+
Fixed visual bug for avatar shape prop

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
max-width: 100%;
1111
background: var(--p-surface-neutral);
1212
color: var(--p-icon-subdued);
13-
border-radius: var(--p-border-radius-half);
1413
user-select: none;
1514

1615
@media (forced-colors: active) {
@@ -24,6 +23,10 @@
2423
}
2524
}
2625

26+
.shapeRound {
27+
border-radius: var(--p-border-radius-half);
28+
}
29+
2730
.shapeSquare {
2831
border-radius: var(--p-border-radius-05);
2932
}
@@ -83,7 +86,7 @@
8386
left: 50%;
8487
width: 100%;
8588
height: 100%;
86-
border-radius: var(--p-border-radius-half);
89+
border-radius: inherit;
8790
transform: translate(-50%, -50%);
8891
object-fit: cover;
8992
}

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useCallback, useState} from 'react';
22
import type {ComponentMeta} from '@storybook/react';
3-
import {ActionList, Avatar, Button, Popover} from '@shopify/polaris';
3+
import {ActionList, Avatar, Button, Popover, Stack} from '@shopify/polaris';
44

55
export default {
66
component: Avatar,
@@ -44,3 +44,32 @@ export function ExtraSmall() {
4444
export function Square() {
4545
return <Avatar name="Shop One" shape="square" />;
4646
}
47+
48+
export function ExternalImage() {
49+
return (
50+
<Avatar
51+
name="External image"
52+
shape="square"
53+
source="https://picsum.photos/200"
54+
/>
55+
);
56+
}
57+
58+
export function Sizes() {
59+
return (
60+
<Stack>
61+
<Stack.Item>
62+
<Avatar customer name="Farrah" size="extraSmall" />
63+
</Stack.Item>
64+
<Stack.Item>
65+
<Avatar customer name="Farrah" size="small" />
66+
</Stack.Item>
67+
<Stack.Item>
68+
<Avatar customer name="Farrah" size="medium" />
69+
</Stack.Item>
70+
<Stack.Item>
71+
<Avatar customer name="Farrah" size="large" />
72+
</Stack.Item>
73+
</Stack>
74+
);
75+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,13 @@ describe('<Avatar />', () => {
138138
className: expect.stringContaining('shapeSquare'),
139139
});
140140
});
141+
142+
it('renders a round background when square is not passed to shape', () => {
143+
const avatar = mountWithApp(<Avatar initials="DL" />);
144+
145+
expect(avatar).toContainReactComponent('span', {
146+
className: expect.stringContaining('shapeRound'),
147+
});
148+
});
141149
});
142150
});

0 commit comments

Comments
 (0)