Skip to content

Commit 28703c9

Browse files
musaleMnickiigavinbarron
authored
fix: add a title text if displaying images only. (#2625)
add a title attribute if displaying profile avatar/initials. --------- Signed-off-by: Martin Musale <[email protected]> Co-authored-by: Nickii Miaro <[email protected]> Co-authored-by: Gavin Barron <[email protected]>
1 parent 7fb265c commit 28703c9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,15 @@ export class MgtPerson extends MgtTemplatedComponent {
705705
*/
706706
protected renderImage(personDetailsInternal: IDynamicPerson, imageSrc: string) {
707707
const altText = `${this.strings.photoFor} ${personDetailsInternal.displayName}`;
708-
const hasImage = imageSrc && !this._isInvalidImageSrc && this._avatarType === 'photo';
709-
const imageTemplate = html`<img alt=${altText} src=${imageSrc} @error=${() => (this._isInvalidImageSrc = true)} />`;
708+
const hasImage = imageSrc && !this._isInvalidImageSrc && this._avatarType === avatarType.photo;
709+
const imageOnly = this.avatarType === avatarType.photo && this.view === ViewType.image;
710+
const titleText =
711+
(personDetailsInternal?.displayName || getEmailFromGraphEntity(personDetailsInternal)) ?? undefined;
712+
const imageTemplate = html`<img
713+
title="${ifDefined(imageOnly ? titleText : undefined)}"
714+
alt=${altText}
715+
src=${imageSrc}
716+
@error=${() => (this._isInvalidImageSrc = true)} />`;
710717

711718
const initials = personDetailsInternal ? this.getInitials(personDetailsInternal) : '';
712719
const hasInitials = initials?.length;
@@ -719,6 +726,7 @@ export class MgtPerson extends MgtTemplatedComponent {
719726
// this reduces the redundant announcement of the user's name.
720727
const textTemplate = html`
721728
<span
729+
title="${ifDefined(this.view === ViewType.image ? titleText : undefined)}"
722730
role="${ifDefined(this.view === ViewType.image ? undefined : 'presentation')}"
723731
class="${textClasses}"
724732
>

packages/mgt-components/src/graph/graph.people.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ export const getPeople = async (
224224
};
225225

226226
/**
227-
* returns a promise that resolves after specified time
227+
* Attempts to extract the email from the IDynamicPerson properties.
228228
*
229-
* @param time in milliseconds
229+
* @param {IDynamicperson} entity
230230
*/
231231
export const getEmailFromGraphEntity = (entity: IDynamicPerson): string => {
232232
const person = entity as Person;

0 commit comments

Comments
 (0)