Skip to content

Commit 65564f4

Browse files
feat(ui5-user-menu): add support for avatar schema color (#13020)
1 parent d28a19a commit 65564f4

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

packages/fiori/cypress/specs/UserMenu.cy.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,73 @@ describe("Avatar configuration", () => {
430430
cy.get("@avatar").find("[ui5-tag]").should("exist");
431431
cy.get("@avatar").find("[ui5-tag]").should("have.length", 1);
432432
});
433+
434+
it("tests avatarColorScheme default value", () => {
435+
cy.mount(
436+
<>
437+
<Button id="openUserMenuBtn">Open User Menu</Button>
438+
<UserMenu open={true} opener="openUserMenuBtn">
439+
<UserMenuAccount
440+
slot="accounts"
441+
avatarInitials="AC"
442+
titleText="Alain Chevalier 1">
443+
</UserMenuAccount>
444+
</UserMenu>
445+
</>
446+
);
447+
cy.get("[ui5-user-menu]").as("userMenu");
448+
cy.get("@userMenu").shadow().find("[ui5-avatar]").as("avatar");
449+
cy.get("@avatar").should("have.attr", "color-scheme", "Auto");
450+
});
451+
452+
it("tests avatarColorScheme with custom value", () => {
453+
cy.mount(
454+
<>
455+
<Button id="openUserMenuBtn">Open User Menu</Button>
456+
<UserMenu open={true} opener="openUserMenuBtn">
457+
<UserMenuAccount
458+
slot="accounts"
459+
avatarInitials="AC"
460+
avatarColorScheme="Accent3"
461+
titleText="Alain Chevalier 1">
462+
</UserMenuAccount>
463+
</UserMenu>
464+
</>
465+
);
466+
cy.get("[ui5-user-menu]").as("userMenu");
467+
cy.get("@userMenu").shadow().find("[ui5-avatar]").as("avatar");
468+
cy.get("@avatar").should("have.attr", "color-scheme", "Accent3");
469+
});
470+
471+
it("tests avatarColorScheme on other accounts", () => {
472+
cy.mount(
473+
<>
474+
<Button id="openUserMenuBtn">Open User Menu</Button>
475+
<UserMenu open={true} opener="openUserMenuBtn" showOtherAccounts={true}>
476+
<UserMenuAccount
477+
slot="accounts"
478+
avatarInitials="AC"
479+
avatarColorScheme="Accent1"
480+
titleText="Alain Chevalier 1"
481+
selected={true}>
482+
</UserMenuAccount>
483+
<UserMenuAccount
484+
slot="accounts"
485+
avatarInitials="JD"
486+
avatarColorScheme="Accent5"
487+
titleText="John Doe">
488+
</UserMenuAccount>
489+
</UserMenu>
490+
</>
491+
);
492+
cy.get("[ui5-user-menu]").as("userMenu");
493+
cy.get("@userMenu").shadow().find(".ui5-user-menu-selected-account-avatar").as("selectedAvatar");
494+
cy.get("@selectedAvatar").should("have.attr", "color-scheme", "Accent1");
495+
cy.get("@userMenu").shadow().find("[ui5-panel]").shadow().find("[ui5-button]").click();
496+
cy.get("@userMenu").shadow().find("[ui5-panel]").find("[ui5-avatar]").as("otherAvatars");
497+
cy.get("@otherAvatars").eq(0).should("have.attr", "color-scheme", "Accent1");
498+
cy.get("@otherAvatars").eq(1).should("have.attr", "color-scheme", "Accent5");
499+
});
433500
});
434501

435502
describe("Events", () => {

packages/fiori/src/UserMenuAccount.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
22
import { customElement, property } from "@ui5/webcomponents-base/dist/decorators.js";
3+
import type AvatarColorScheme from "@ui5/webcomponents/dist/types/AvatarColorScheme.js";
34

45
@customElement({
56
tag: "ui5-user-menu-account",
@@ -38,6 +39,16 @@ class UserMenuAccount extends UI5Element {
3839
@property({ type: String })
3940
avatarInitials?: string;
4041

42+
/**
43+
* Defines the background color of the desired image.
44+
* If `avatarColorScheme` is set to `Auto`, the avatar will be displayed with the `Accent6` color.
45+
*
46+
* @default "Auto"
47+
* @public
48+
*/
49+
@property()
50+
avatarColorScheme: `${AvatarColorScheme}` = "Auto";
51+
4152
/**
4253
* Defines the title text of the user.
4354
*

packages/fiori/src/UserMenuTemplate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function headerContent(this: UserMenu) {
9595
return (<>
9696
{this._selectedAccount &&
9797
<div class="ui5-user-menu-selected-account" aria-label={this._ariaLabelledByAccountInformationText}>
98-
<Avatar size="L" onClick={this._handleAvatarClick} initials={this._selectedAccount._initials} fallbackIcon={personPlaceholder} class="ui5-user-menu-selected-account-avatar" interactive>
98+
<Avatar size="L" onClick={this._handleAvatarClick} initials={this._selectedAccount._initials} colorScheme={this._selectedAccount.avatarColorScheme} fallbackIcon={personPlaceholder} class="ui5-user-menu-selected-account-avatar" interactive>
9999
{this._selectedAccount.avatarSrc &&
100100
<img src={this._selectedAccount.avatarSrc} title={this.showEditButton ? this._editAvatarTooltip : undefined }/>
101101
}
@@ -159,7 +159,7 @@ function otherAccountsList(this: UserMenu) {
159159
aria-label={account.titleText}
160160
>
161161
<div class="ui5-user-menu-other-accounts-content">
162-
<Avatar slot="image" size="S" initials={account._initials} fallbackIcon={personPlaceholder}>
162+
<Avatar slot="image" size="S" initials={account._initials} fallbackIcon={personPlaceholder} colorScheme={account.avatarColorScheme}>
163163
{account.avatarSrc &&
164164
<img src={account.avatarSrc}/>
165165
}

0 commit comments

Comments
 (0)