Skip to content

Commit 661fc8e

Browse files
authored
Merge pull request #388 from microsoftgraph/nmetulev/387
Fixed person initials for non English letters
2 parents 45774d2 + f873556 commit 661fc8e

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/components/mgt-person/mgt-person.scss

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,24 @@ mgt-person .user-avatar {
7474
border-radius: 50%;
7575
font-weight: 400;
7676

77-
& .initials-text {
77+
& .initials-text,
78+
& .ms-Icon {
7879
cursor: default;
7980
margin-top: -1px;
8081
font-size: calc(var(--avatar-size, 48px) * 0.4);
8182
}
83+
84+
& .ms-Icon {
85+
display: inline;
86+
}
8287
}
8388

8489
&.small {
8590
width: $avatar-size-s;
8691
height: $avatar-size-s;
8792

88-
& .initials-text {
93+
& .initials-text,
94+
& .ms-Icon {
8995
font-size: calc(var(--avatar-size-s, 24px) * 0.4);
9096
}
9197
}

src/components/mgt-person/mgt-person.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ export class MgtPerson extends MgtTemplatedComponent {
312312
this.personDetails && this.personCardInteraction === PersonCardInteraction.none
313313
? this.personDetails.displayName
314314
: '';
315+
315316
const isLarge = this.showEmail && this.showName;
316317
const imageClasses = {
317318
initials: !imageSrc,
@@ -321,19 +322,31 @@ export class MgtPerson extends MgtTemplatedComponent {
321322
};
322323

323324
let imageHtml: TemplateResult;
325+
324326
if (imageSrc) {
325327
// render the image
326328
imageHtml = html`
327329
<img alt=${title} src=${imageSrc} />
328330
`;
329331
} else if (this.personDetails) {
330-
// render the initials
331-
const initials = this.getInitials(this.personDetails);
332+
// render the initials or person icon
333+
332334
// add avatar background color
333335
imageClasses[this._personAvatarBg] = true;
336+
337+
const initials = this.getInitials(this.personDetails);
338+
const initialsHtml =
339+
initials && initials.length
340+
? html`
341+
${initials}
342+
`
343+
: html`
344+
<i class="ms-Icon ms-Icon--Contact"></i>
345+
`;
346+
334347
imageHtml = html`
335348
<span class="initials-text" aria-label="${initials}">
336-
${initials}
349+
${initialsHtml}
337350
</span>
338351
`;
339352
} else {
@@ -572,7 +585,7 @@ export class MgtPerson extends MgtTemplatedComponent {
572585
if (!initials && person.displayName) {
573586
const name = person.displayName.split(/\s+/);
574587
for (let i = 0; i < 2 && i < name.length; i++) {
575-
if (name[i][0] && name[i][0].match(/[a-z]/i)) {
588+
if (name[i][0] && name[i][0].match(/\p{L}/gu)) {
576589
// check if letter
577590
initials += name[i][0].toUpperCase();
578591
}

0 commit comments

Comments
 (0)