Skip to content

Commit

Permalink
fix: add a title text if displaying images only. (#2625)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
3 people committed Aug 21, 2023
1 parent 302b3bf commit d671d3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions packages/mgt-components/src/components/mgt-person/mgt-person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,15 @@ export class MgtPerson extends MgtTemplatedComponent {
*/
protected renderImage(personDetailsInternal: IDynamicPerson, imageSrc: string) {
const altText = `${this.strings.photoFor} ${personDetailsInternal.displayName}`;
const hasImage = imageSrc && !this._isInvalidImageSrc && this._avatarType === 'photo';
const imageTemplate = html`<img alt=${altText} src=${imageSrc} @error=${() => (this._isInvalidImageSrc = true)} />`;
const hasImage = imageSrc && !this._isInvalidImageSrc && this._avatarType === avatarType.photo;
const imageOnly = this.avatarType === avatarType.photo && this.view === ViewType.image;
const titleText =
(personDetailsInternal?.displayName || getEmailFromGraphEntity(personDetailsInternal)) ?? undefined;
const imageTemplate = html`<img
title="${ifDefined(imageOnly ? titleText : undefined)}"
alt=${altText}
src=${imageSrc}
@error=${() => (this._isInvalidImageSrc = true)} />`;

const initials = personDetailsInternal ? this.getInitials(personDetailsInternal) : '';
const hasInitials = initials?.length;
Expand All @@ -719,6 +726,7 @@ export class MgtPerson extends MgtTemplatedComponent {
// this reduces the redundant announcement of the user's name.
const textTemplate = html`
<span
title="${ifDefined(this.view === ViewType.image ? titleText : undefined)}"
role="${ifDefined(this.view === ViewType.image ? undefined : 'presentation')}"
class="${textClasses}"
>
Expand Down
4 changes: 2 additions & 2 deletions packages/mgt-components/src/graph/graph.people.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ export const getPeople = async (
};

/**
* returns a promise that resolves after specified time
* Attempts to extract the email from the IDynamicPerson properties.
*
* @param time in milliseconds
* @param {IDynamicperson} entity
*/
export const getEmailFromGraphEntity = (entity: IDynamicPerson): string => {
const person = entity as Person;
Expand Down

0 comments on commit d671d3c

Please sign in to comment.