Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close user profile menu after menu entry is selected #3224

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/shared/auth-nav-menu/auth-nav-menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</div>
</div>
<div *ngIf="(isAuthenticated | async) && (showAuth | async)" class="nav-item">
<div ngbDropdown display="dynamic" placement="bottom-right" class="d-inline-block" @fadeInOut>
<div ngbDropdown #loggedInDrop="ngbDropdown" display="dynamic" placement="bottom-right" class="d-inline-block" @fadeInOut>
<a href="javascript:void(0);"
role="menuitem"
[attr.aria-label]="'nav.user-profile-menu-and-logout' | translate"
Expand All @@ -30,7 +30,7 @@
ngbDropdownToggle>
<i class="fas fa-user-circle fa-lg fa-fw"></i></a>
<div id="logoutDropdownMenu" ngbDropdownMenu>
<ds-user-menu [inExpandableNavbar]="false"></ds-user-menu>
<ds-user-menu [inExpandableNavbar]="false" (changedRoute)="loggedInDrop.close()"></ds-user-menu>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
Component,
EventEmitter,
Input,
Output,
} from '@angular/core';

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

protected inAndOutputNames: (keyof UserMenuComponent & keyof this)[] = ['inExpandableNavbar'];
/**
* Emits an event when the route changes
*/
@Output() changedRoute: EventEmitter<any> = new EventEmitter<any>();

protected inAndOutputNames: (keyof UserMenuComponent & keyof this)[] = ['inExpandableNavbar', 'changedRoute'];

protected getComponentName(): string {
return 'UserMenuComponent';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
{{dsoNameService.getName(user$ | async)}}<br>
<span class="text-muted">{{(user$ | async)?.email}}</span>
</li>
<li class="ds-menu-item-wrapper" role="presentation">
<li class="ds-menu-item-wrapper" role="presentation" (click)="onMenuItemClick()">
<a class="ds-menu-item" role="menuitem"
[routerLink]="[profileRoute]"
routerLinkActive="active">{{'nav.profile' | translate}}</a>
</li>
<li class="ds-menu-item-wrapper" role="presentation">
<li class="ds-menu-item-wrapper" role="presentation" (click)="onMenuItemClick()">
<a class="ds-menu-item" role="menuitem"
[routerLink]="[mydspaceRoute]"
routerLinkActive="active">{{'nav.mydspace' | translate}}</a>
</li>
<li class="ds-menu-item-wrapper" role="presentation">
<li class="ds-menu-item-wrapper" role="presentation" (click)="onMenuItemClick()">
<a class="ds-menu-item" role="menuitem"
[routerLink]="[subscriptionsRoute]"
routerLinkActive="active">{{'nav.subscriptions' | translate}}</a>
Expand Down
11 changes: 11 additions & 0 deletions src/app/shared/auth-nav-menu/user-menu/user-menu.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,17 @@ describe('UserMenuComponent', () => {
expect(components).toBeFalsy();
});

it('should call onMenuItemClick when li is clicked', () => {
spyOn(component, 'onMenuItemClick');
const lis = fixture.debugElement.queryAll(By.css('.ds-menu-item-wrapper'));
const secondLi = lis[1];
secondLi.triggerEventHandler('click', {
preventDefault: () => {/**/
},
});
expect(component.onMenuItemClick).toHaveBeenCalled();
});

});

});
14 changes: 14 additions & 0 deletions src/app/shared/auth-nav-menu/user-menu/user-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
} from '@angular/common';
import {
Component,
EventEmitter,
Input,
OnInit,
Output,
} from '@angular/core';
import {
RouterLink,
Expand Down Expand Up @@ -49,6 +51,11 @@ export class UserMenuComponent implements OnInit {
*/
@Input() inExpandableNavbar = false;

/**
* Emits an event when the route changes
*/
@Output() changedRoute: EventEmitter<any> = new EventEmitter<any>();

/**
* True if the authentication is loading.
* @type {Observable<boolean>}
Expand Down Expand Up @@ -96,4 +103,11 @@ export class UserMenuComponent implements OnInit {
this.user$ = this.authService.getAuthenticatedUserFromStore();

}

/**
* Emits an event when the menu item is clicked
*/
onMenuItemClick() {
this.changedRoute.emit();
}
}
Loading