Skip to content

Commit 1a72666

Browse files
authored
Fix initials logic (#361)
* Fix initials logic Fixes #360 This feels like the correct logic to me but I'm happy to be contradicted - the display name stuff is what is erroring * Fix build issues Fix build issues
1 parent d351d09 commit 1a72666

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ export class MgtPerson extends MgtTemplatedComponent {
569569
person = this.personDetails;
570570
}
571571

572+
if ((person as MicrosoftGraph.Contact).initials) {
573+
return (person as MicrosoftGraph.Contact).initials;
574+
}
575+
572576
let initials = '';
573577
if (person.givenName) {
574578
initials += person.givenName[0].toUpperCase();
@@ -578,9 +582,9 @@ export class MgtPerson extends MgtTemplatedComponent {
578582
}
579583

580584
if (!initials && person.displayName) {
581-
const name = person.displayName.split(' ');
585+
const name = person.displayName.split(/\s+/);
582586
for (let i = 0; i < 2 && i < name.length; i++) {
583-
if (name[i][0].match(/[a-z]/i)) {
587+
if (name[i][0] && name[i][0].match(/[a-z]/i)) {
584588
// check if letter
585589
initials += name[i][0].toUpperCase();
586590
}

0 commit comments

Comments
 (0)