@@ -20,7 +20,7 @@ import WebCButton from "@ui5/webcomponents/dist/Button";
2020import WebCPopover from "@ui5/webcomponents/dist/Popover" ;
2121import WebCFUserMenu , { UserMenuItemClickEventDetail } from "@ui5/webcomponents-fiori/dist/UserMenu" ;
2222import 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
2626import "@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 > ;
0 commit comments