Skip to content

Commit 643b3a3

Browse files
committed
Merge branch 'main' of https://github.com/StackExchange/Stacks into alpha
2 parents 98e4f5e + c0df419 commit 643b3a3

5 files changed

Lines changed: 126 additions & 52 deletions

File tree

.changeset/strong-news-float.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@stackoverflow/stacks-svelte": patch
3+
---
4+
5+
* `<Avatar>` nested `<img>` dimensions.
6+
* Screen reader text for the private badge variant.

package-lock.json

Lines changed: 59 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"globals": "^17.0.0",
7272
"htm": "^3.1.1",
7373
"less-loader": "^12.3.0",
74-
"markdown-it": "^14.1.0",
74+
"markdown-it": "^14.1.1",
7575
"mini-css-extract-plugin": "^2.9.4",
7676
"postcss-less": "^6.0.0",
7777
"postcss-loader": "^8.2.0",

packages/stacks-svelte/src/components/Avatar/Avatar.svelte

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
* Additional CSS classes added to the element
4949
*/
5050
class?: string;
51+
52+
/**
53+
* Localized translation for private communities icon title tag
54+
*/
55+
i18nPrivateIconTitle?: string;
5156
}
5257
5358
const {
@@ -60,6 +65,7 @@
6065
badge = false,
6166
class: className = "",
6267
role,
68+
i18nPrivateIconTitle = "Private",
6369
...restProps
6470
}: Props & HTMLAnchorAttributes = $props();
6571
@@ -89,7 +95,14 @@
8995
{...restProps}
9096
>
9197
{#if src}
92-
<img class="s-avatar--image" {src} alt="" role="presentation" />
98+
<img
99+
class="s-avatar--image"
100+
{src}
101+
alt=""
102+
role="presentation"
103+
width={size}
104+
height={size}
105+
/>
93106
{:else if letter}
94107
<span class="s-avatar--letter" aria-hidden="true">{letter}</span>
95108
{/if}
@@ -103,8 +116,11 @@
103116
/>
104117
{/if}
105118
{#if badge}
106-
<!-- TODO This badge is not purely decorative, so it should include descriptive text
107-
(see https://stackoverflow.atlassian.net/browse/A11Y-126) -->
108-
<Icon class="s-avatar--badge" src={IconShieldXSm} native />
119+
<Icon
120+
class="s-avatar--badge"
121+
src={IconShieldXSm}
122+
native
123+
title={i18nPrivateIconTitle}
124+
/>
109125
{/if}
110126
</svelte:element>

packages/stacks-svelte/src/components/Avatar/Avatar.test.ts

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,33 @@ describe("Avatar", () => {
3535
expect(screen.getByText("test avatar")).to.exist;
3636
});
3737

38+
it("should set width and height on the image from size", () => {
39+
const { container } = render(Avatar, {
40+
name: "test avatar",
41+
src: "https://picsum.photos/128",
42+
size: 48,
43+
});
44+
const imageElement = container.querySelector(
45+
".s-avatar--image"
46+
) as HTMLImageElement | null;
47+
expect(imageElement).to.exist;
48+
expect(imageElement).to.have.attr("width", "48");
49+
expect(imageElement).to.have.attr("height", "48");
50+
});
51+
52+
it("should default image width and height to 16 when size is omitted", () => {
53+
const { container } = render(Avatar, {
54+
name: "test avatar",
55+
src: "https://picsum.photos/128",
56+
});
57+
const imageElement = container.querySelector(
58+
".s-avatar--image"
59+
) as HTMLImageElement | null;
60+
expect(imageElement).to.exist;
61+
expect(imageElement).to.have.attr("width", "16");
62+
expect(imageElement).to.have.attr("height", "16");
63+
});
64+
3865
it("should render the avatar with the provided letter", () => {
3966
render(Avatar, {
4067
name: "test avatar",
@@ -57,31 +84,25 @@ describe("Avatar", () => {
5784
expect(badgeElement).to.exist;
5885
});
5986

60-
it("should render the online status small indicator when status is online and size is 16 or 24", () => {
61-
render(Avatar, {
87+
it("should use default i18nPrivateIconTitle for the badge icon", () => {
88+
const { container } = render(Avatar, {
6289
name: "test avatar",
63-
status: "online",
90+
badge: true,
6491
});
65-
const smallIndicatorEl = screen
66-
.getByText("test avatar")
67-
.parentElement?.querySelector(".s-avatar--indicator");
68-
expect(smallIndicatorEl).to.exist;
69-
expect(smallIndicatorEl).to.have.class("s-activity-indicator__sm");
70-
expect(screen.getByText("Online")).to.exist;
92+
const title = container.querySelector(".s-avatar--badge title");
93+
expect(title).to.exist;
94+
expect(title?.textContent).to.equal("Private");
7195
});
7296

73-
it("should render the online status large indicator when status is online and size is above 24", () => {
74-
render(Avatar, {
97+
it("should use custom i18nPrivateIconTitle for the badge icon", () => {
98+
const { container } = render(Avatar, {
7599
name: "test avatar",
76-
status: "online",
77-
size: 32,
100+
badge: true,
101+
i18nPrivateIconTitle: "Community privée",
78102
});
79-
const largeIndicatorEl = screen
80-
.getByText("test avatar")
81-
.parentElement?.querySelector(".s-avatar--indicator");
82-
expect(largeIndicatorEl).to.exist;
83-
expect(largeIndicatorEl).not.to.have.class("s-activity-indicator__sm");
84-
expect(screen.getByText("Online")).to.exist;
103+
const title = container.querySelector(".s-avatar--badge title");
104+
expect(title).to.exist;
105+
expect(title?.textContent).to.equal("Community privée");
85106
});
86107

87108
it("should render the avatar with artbirary classes", () => {

0 commit comments

Comments
 (0)