Skip to content

Commit ab691c4

Browse files
committed
fix: handle empty avatar state
1 parent 9a3f9c3 commit ab691c4

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/avatar/avatar.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
background-color: var(--reactist-avatar-meta-fill);
6363
}
6464

65+
.empty {
66+
background-color: var(--reactist-avatar-empty-fill);
67+
}
68+
6569
.shape-circle {
6670
border-radius: 50%;
6771
}

src/avatar/avatar.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ function AvatarContent({
101101
const availableImageSources = getAvailableImageSources(imageSources, failedImageSources)
102102

103103
const initials = getInitials(name)
104+
const hasInitials = initials !== ''
104105
const label = alt ?? name
105106
const isDecorative = label === ''
106107

@@ -109,10 +110,12 @@ function AvatarContent({
109110
className={classNames(
110111
styles.avatar,
111112
styles[`shape-${shape}`],
113+
!availableImageSources && !hasInitials && styles.empty,
112114
exceptionallySetClassName,
113115
)}
114116
style={getAvatarStyle(size, name)}
115117
data-testid={testId}
118+
aria-hidden={isDecorative || undefined}
116119
display="inlineFlex"
117120
alignItems="center"
118121
justifyContent="center"
@@ -141,7 +144,7 @@ function AvatarContent({
141144
)
142145
}}
143146
/>
144-
) : (
147+
) : hasInitials ? (
145148
<div
146149
className={styles.initials}
147150
role={label ? 'img' : undefined}
@@ -150,7 +153,7 @@ function AvatarContent({
150153
>
151154
{initials}
152155
</div>
153-
)}
156+
) : null}
154157
</Box>
155158
)
156159
}

0 commit comments

Comments
 (0)