Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 0d1fce3

Browse files
authored
Fix layout and visual regressions around default avatars (#10031)
1 parent 5a08859 commit 0d1fce3

File tree

5 files changed

+21
-28
lines changed

5 files changed

+21
-28
lines changed

cypress/e2e/spaces/spaces.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ describe("Spaces", () => {
153153

154154
openSpaceCreateMenu().within(() => {
155155
cy.get(".mx_SpaceCreateMenuType_private").click();
156-
cy.get('.mx_SpaceBasicSettings_avatarContainer input[type="file"]').selectFile(
157-
"cypress/fixtures/riot.png",
158-
{ force: true },
159-
);
156+
// We don't set an avatar here to get a Percy snapshot of the default avatar style for spaces
160157
cy.get('input[label="Address"]').should("not.exist");
161158
cy.get('textarea[label="Description"]').type("This is a personal space to mourn Riot.im...");
162159
cy.get('input[label="Name"]').type("This is my Riot{enter}");
@@ -169,6 +166,7 @@ describe("Spaces", () => {
169166

170167
cy.contains(".mx_RoomList .mx_RoomTile", "Sample Room").should("exist");
171168
cy.contains(".mx_SpaceHierarchy_list .mx_SpaceHierarchy_roomTile", "Sample Room").should("exist");
169+
cy.get(".mx_LeftPanel_outerWrapper").percySnapshotElement("Left panel with default avatar space");
172170
});
173171

174172
it("should allow user to invite another to a space", () => {

res/css/structures/_SpacePanel.pcss

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,11 @@ $activeBorderColor: $primary-content;
277277
.mx_BaseAvatar:not(.mx_UserMenu_userAvatar_BaseAvatar) .mx_BaseAvatar_initial {
278278
color: $secondary-content;
279279
border-radius: 8px;
280-
background-color: $panel-actions;
281-
font-size: $font-15px !important; /* override inline style */
282280
font-weight: $font-semi-bold;
283281
line-height: $font-18px;
284-
285-
& + .mx_BaseAvatar_image {
286-
visibility: hidden;
287-
}
282+
/* override inline styles which are part of the default avatar style as these uses a monochrome style */
283+
background-color: $panel-actions !important;
284+
font-size: $font-15px !important;
288285
}
289286

290287
.mx_SpaceTreeLevel {

res/css/structures/_UserMenu.pcss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ limitations under the License.
2525

2626
.mx_UserMenu_userAvatar {
2727
position: relative;
28+
/* without this a default avatar will cause this to be 4px oversized and out of alignment */
29+
display: inherit;
2830

2931
.mx_BaseAvatar {
3032
pointer-events: none; /* makes the avatar non-draggable */

src/components/views/avatars/BaseAvatar.tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
1717

18-
import React, { useCallback, useContext, useEffect, useState } from "react";
18+
import React, { CSSProperties, useCallback, useContext, useEffect, useState } from "react";
1919
import classNames from "classnames";
2020
import { ResizeMethod } from "matrix-js-sdk/src/@types/partials";
2121
import { ClientEvent } from "matrix-js-sdk/src/client";
@@ -51,6 +51,7 @@ interface IProps {
5151
inputRef?: React.RefObject<HTMLImageElement & HTMLSpanElement>;
5252
className?: string;
5353
tabIndex?: number;
54+
style?: CSSProperties;
5455
}
5556

5657
const calculateUrls = (url: string | undefined, urls: string[] | undefined, lowBandwidth: boolean): string[] => {
@@ -132,10 +133,17 @@ const BaseAvatar: React.FC<IProps> = (props) => {
132133
onClick,
133134
inputRef,
134135
className,
136+
style: parentStyle,
135137
resizeMethod: _unused, // to keep it from being in `otherProps`
136138
...otherProps
137139
} = props;
138140

141+
const style = {
142+
...parentStyle,
143+
width: toPx(width),
144+
height: toPx(height),
145+
};
146+
139147
const [imageUrl, onError] = useImageUrl({ url, urls });
140148

141149
if (!imageUrl && defaultToInitialLetter && name) {
@@ -151,10 +159,7 @@ const BaseAvatar: React.FC<IProps> = (props) => {
151159
className={classNames("mx_BaseAvatar", className)}
152160
onClick={onClick}
153161
inputRef={inputRef}
154-
style={{
155-
width: toPx(width),
156-
height: toPx(height),
157-
}}
162+
style={style}
158163
>
159164
{avatar}
160165
</AccessibleButton>
@@ -165,10 +170,7 @@ const BaseAvatar: React.FC<IProps> = (props) => {
165170
className={classNames("mx_BaseAvatar", className)}
166171
ref={inputRef}
167172
{...otherProps}
168-
style={{
169-
width: toPx(width),
170-
height: toPx(height),
171-
}}
173+
style={style}
172174
role="presentation"
173175
>
174176
{avatar}
@@ -185,10 +187,7 @@ const BaseAvatar: React.FC<IProps> = (props) => {
185187
src={imageUrl}
186188
onClick={onClick}
187189
onError={onError}
188-
style={{
189-
width: toPx(width),
190-
height: toPx(height),
191-
}}
190+
style={style}
192191
title={title}
193192
alt={_t("Avatar")}
194193
inputRef={inputRef}
@@ -202,10 +201,7 @@ const BaseAvatar: React.FC<IProps> = (props) => {
202201
className={classNames("mx_BaseAvatar mx_BaseAvatar_image", className)}
203202
src={imageUrl}
204203
onError={onError}
205-
style={{
206-
width: toPx(width),
207-
height: toPx(height),
208-
}}
204+
style={style}
209205
title={title}
210206
alt=""
211207
ref={inputRef}

test/components/views/avatars/__snapshots__/MemberAvatar-test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exports[`MemberAvatar matches the snapshot 1`] = `
77
class="mx_BaseAvatar mx_BaseAvatar_image"
88
data-testid="avatar-img"
99
src="http://this.is.a.url//placekitten.com/400/400"
10-
style="color: pink;"
10+
style="color: pink; width: 35px; height: 35px;"
1111
title="Hover title"
1212
/>
1313
</div>

0 commit comments

Comments
 (0)