Skip to content

Commit 3bd84a6

Browse files
[CST-15590] Close user profile menu after menu entry is selected (#3760)
(cherry picked from commit fa0ec0b) Co-authored-by: Alisa Ismailati <alisa.ismailati@4science.com>
1 parent e842c06 commit 3bd84a6

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

src/app/shared/auth-nav-menu/auth-nav-menu.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</div>
2020
</div>
2121
<div *ngIf="(isAuthenticated | async) && (showAuth | async)" class="nav-item">
22-
<div ngbDropdown display="dynamic" placement="bottom-right" class="d-inline-block" @fadeInOut>
22+
<div ngbDropdown #loggedInDrop="ngbDropdown" display="dynamic" placement="bottom-right" class="d-inline-block" @fadeInOut>
2323
<a href="javascript:void(0);"
2424
role="menuitem"
2525
[attr.aria-label]="'nav.user-profile-menu-and-logout' | translate"
@@ -30,7 +30,7 @@
3030
ngbDropdownToggle>
3131
<i class="fas fa-user-circle fa-lg fa-fw"></i></a>
3232
<div id="logoutDropdownMenu" ngbDropdownMenu>
33-
<ds-user-menu [inExpandableNavbar]="false"></ds-user-menu>
33+
<ds-user-menu [inExpandableNavbar]="false" (changedRoute)="loggedInDrop.close()"></ds-user-menu>
3434
</div>
3535
</div>
3636
</div>

src/app/shared/auth-nav-menu/user-menu/themed-user-menu.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
Component,
3+
EventEmitter,
34
Input,
5+
Output,
46
} from '@angular/core';
57

68
import { ThemedComponent } from '../../theme-support/themed.component';
@@ -23,7 +25,12 @@ export class ThemedUserMenuComponent extends ThemedComponent<UserMenuComponent>{
2325
*/
2426
@Input() inExpandableNavbar: boolean;
2527

26-
protected inAndOutputNames: (keyof UserMenuComponent & keyof this)[] = ['inExpandableNavbar'];
28+
/**
29+
* Emits an event when the route changes
30+
*/
31+
@Output() changedRoute: EventEmitter<any> = new EventEmitter<any>();
32+
33+
protected inAndOutputNames: (keyof UserMenuComponent & keyof this)[] = ['inExpandableNavbar', 'changedRoute'];
2734

2835
protected getComponentName(): string {
2936
return 'UserMenuComponent';

src/app/shared/auth-nav-menu/user-menu/user-menu.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
{{dsoNameService.getName(user$ | async)}}<br>
77
<span class="text-muted">{{(user$ | async)?.email}}</span>
88
</li>
9-
<li class="ds-menu-item-wrapper" role="presentation">
9+
<li class="ds-menu-item-wrapper" role="presentation" (click)="onMenuItemClick()">
1010
<a class="ds-menu-item" role="menuitem"
1111
[routerLink]="[profileRoute]"
1212
routerLinkActive="active">{{'nav.profile' | translate}}</a>
1313
</li>
14-
<li class="ds-menu-item-wrapper" role="presentation">
14+
<li class="ds-menu-item-wrapper" role="presentation" (click)="onMenuItemClick()">
1515
<a class="ds-menu-item" role="menuitem"
1616
[routerLink]="[mydspaceRoute]"
1717
routerLinkActive="active">{{'nav.mydspace' | translate}}</a>
1818
</li>
19-
<li class="ds-menu-item-wrapper" role="presentation">
19+
<li class="ds-menu-item-wrapper" role="presentation" (click)="onMenuItemClick()">
2020
<a class="ds-menu-item" role="menuitem"
2121
[routerLink]="[subscriptionsRoute]"
2222
routerLinkActive="active">{{'nav.subscriptions' | translate}}</a>

src/app/shared/auth-nav-menu/user-menu/user-menu.component.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ describe('UserMenuComponent', () => {
203203
expect(components).toBeFalsy();
204204
});
205205

206+
it('should call onMenuItemClick when li is clicked', () => {
207+
spyOn(component, 'onMenuItemClick');
208+
const lis = fixture.debugElement.queryAll(By.css('.ds-menu-item-wrapper'));
209+
const secondLi = lis[1];
210+
secondLi.triggerEventHandler('click', {
211+
preventDefault: () => {/**/
212+
},
213+
});
214+
expect(component.onMenuItemClick).toHaveBeenCalled();
215+
});
216+
206217
});
207218

208219
});

src/app/shared/auth-nav-menu/user-menu/user-menu.component.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
} from '@angular/common';
66
import {
77
Component,
8+
EventEmitter,
89
Input,
910
OnInit,
11+
Output,
1012
} from '@angular/core';
1113
import {
1214
RouterLink,
@@ -49,6 +51,11 @@ export class UserMenuComponent implements OnInit {
4951
*/
5052
@Input() inExpandableNavbar = false;
5153

54+
/**
55+
* Emits an event when the route changes
56+
*/
57+
@Output() changedRoute: EventEmitter<any> = new EventEmitter<any>();
58+
5259
/**
5360
* True if the authentication is loading.
5461
* @type {Observable<boolean>}
@@ -96,4 +103,11 @@ export class UserMenuComponent implements OnInit {
96103
this.user$ = this.authService.getAuthenticatedUserFromStore();
97104

98105
}
106+
107+
/**
108+
* Emits an event when the menu item is clicked
109+
*/
110+
onMenuItemClick() {
111+
this.changedRoute.emit();
112+
}
99113
}

0 commit comments

Comments
 (0)