Skip to content

Commit 001b196

Browse files
committed
fix: use ShellBar event targetRef for UserMenu opener
Replace hardcoded profileAvatar ID lookup with event-driven approach using ShellBar$ProfileClickEvent targetRef to properly position UserMenu
1 parent ac0b7e3 commit 001b196

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

webapp/controller/App.controller.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import WebCButton from "@ui5/webcomponents/dist/Button";
2020
import WebCPopover from "@ui5/webcomponents/dist/Popover";
2121
import WebCFUserMenu, { UserMenuItemClickEventDetail } from "@ui5/webcomponents-fiori/dist/UserMenu";
2222
import WebCFUserSettingsDialog from "@ui5/webcomponents-fiori/dist/UserSettingsDialog";
23-
import { ShellBar$NotificationsClickEvent } from "sap/ui/webc/fiori/ShellBar";
23+
import { ShellBar$NotificationsClickEvent, ShellBar$ProfileClickEvent } from "sap/ui/webc/fiori/ShellBar";
2424

2525
// Icons
2626
import "@ui5/webcomponents-icons/dist/menu2";
@@ -175,12 +175,16 @@ export default class App extends BaseController {
175175

176176
/**
177177
* Called when the user clicks on the profile button.
178-
* This is used to open the user settings dialog.
178+
* This is used to open the user menu and setup the settings dialog.
179179
*/
180-
async onProfileClick(): Promise<void> {
180+
async onProfileClick(e: ShellBar$ProfileClickEvent): Promise<void> {
181181
const userMenu = this.getView().byId("userProfileMenu").getDomRef() as WebCFUserMenu;
182+
183+
// Use the targetRef from the event as the opener
184+
userMenu.opener = e.getParameter("targetRef");
182185
userMenu.open = true;
183186

187+
// Load the settings dialog if not already loaded
184188
let settingsDialog = this.getView().byId("settings") as unknown as WebCFUserSettingsDialog;
185189
if (!settingsDialog) {
186190
const dialogFragment = await Fragment.load({
@@ -193,6 +197,7 @@ export default class App extends BaseController {
193197
settingsDialog = dialogFragment as unknown as WebCFUserSettingsDialog;
194198
}
195199

200+
// Add event listener for user menu item clicks if not already added
196201
if (!this.userMenuListenerAdded) {
197202
userMenu.addEventListener("item-click", (event: Event) => {
198203
const customEvent = event as CustomEvent<UserMenuItemClickEventDetail>;

webapp/view/App.view.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<webcf:ShellBarItem icon="sys-help" text="Help" />
8080

8181
<webcf:profile>
82-
<webc:Avatar id="profileAvatar">
82+
<webc:Avatar>
8383
<Image src="images/Avatar.svg" alt="Avatar" />
8484
</webc:Avatar>
8585
</webcf:profile>
@@ -151,7 +151,7 @@
151151
</tnt:mainContents>
152152
</tnt:ToolPage>
153153

154-
<webcf:UserMenu id="userProfileMenu" opener="profileAvatar" showManageAccount="true"
154+
<webcf:UserMenu id="userProfileMenu" showManageAccount="true"
155155
showOtherAccounts="true" showEditAccounts="true" showEditButton="true">
156156
<webcf:accounts>
157157
<webcf:UserMenuAccount titleText="Alain Chevalier" subtitleText="[email protected]"

0 commit comments

Comments
 (0)