Expand menu item clickable area to full width for better UX (#1107)

This commit is contained in:
Aditya Chandel
2025-09-07 10:57:37 -06:00
committed by GitHub
parent ae24cca0e3
commit e693efb410
2 changed files with 82 additions and 60 deletions
@@ -31,49 +31,61 @@
}
<div>
<div class="flex flex-row items-center justify-between hover:bg-surface-800 rounded-md">
<div
class="flex flex-row items-center justify-between hover:bg-surface-800 rounded-md cursor-pointer"
(click)="triggerLink()"
>
@if ((item.routerLink && !item.items)) {
<a
#link
(click)="itemClick($event)"
[ngClass]="item.class"
[routerLink]="item.routerLink" routerLinkActive="active-route"
[ngClass]="item.class + ' flex items-center gap-2 w-full'"
[routerLink]="item.routerLink"
routerLinkActive="active-route"
[routerLinkActiveOptions]="item.routerLinkActiveOptions || { paths: 'exact', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored' }"
[fragment]="item.fragment" [queryParamsHandling]="item.queryParamsHandling"
[fragment]="item.fragment"
[queryParamsHandling]="item.queryParamsHandling"
[preserveFragment]="item.preserveFragment"
[skipLocationChange]="item.skipLocationChange" [replaceUrl]="item.replaceUrl" [state]="item.state"
[skipLocationChange]="item.skipLocationChange"
[replaceUrl]="item.replaceUrl"
[state]="item.state"
[queryParams]="item.queryParams"
[attr.target]="item.target" tabindex="0" pRipple>
[attr.target]="item.target"
tabindex="0"
pRipple
>
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
<span class="layout-menuitem-text w-full truncate">
{{ item.label }}
</span>
{{ item.label }}
</span>
</a>
}
<span>
@if (item.type === 'Library' || item.type === 'Shelf' || item.type === 'magicShelfItem') {
@if ((item.type !== 'Library' || (admin || canManipulateLibrary)) && item.label !== 'Unshelved' && item.label !== 'Kobo') {
<p-button
(click)="entitymenu.toggle($event)"
(mouseover)="hovered = true"
(mouseleave)="hovered = false"
[text]="true"
[outlined]="false"
[rounded]="true"
[label]="hovered ? '' : (item.bookCount$ | async)?.toString() || ''"
[icon]="hovered ? 'pi pi-ellipsis-v' : ''"
[style.height]="'30px'"
[style.display]="'flex'">
</p-button>
}
<p-menu #entitymenu [model]="item.menu" [popup]="true" appendTo="body"></p-menu>
}
@if (item.type === 'Library' || item.type === 'Shelf' || item.type === 'magicShelfItem') {
@if ((item.type !== 'Library' || (admin || canManipulateLibrary)) && item.label !== 'Unshelved' && item.label !== 'Kobo') {
<p-button
(click)="entitymenu.toggle($event); $event.stopPropagation()"
(mouseover)="hovered = true"
(mouseleave)="hovered = false"
[text]="true"
[outlined]="false"
[rounded]="true"
[label]="hovered ? '' : (item.bookCount$ | async)?.toString() || ''"
[icon]="hovered ? 'pi pi-ellipsis-v' : ''"
[style.height]="'30px'"
[style.display]="'flex'"
></p-button>
}
<p-menu #entitymenu [model]="item.menu" [popup]="true" appendTo="body"></p-menu>
}
@if (item.type === 'Library' && (!admin && !canManipulateLibrary) || item.type === 'All Books' || item.label === 'Unshelved' || item.label === 'Kobo') {
<p class="text-[var(--primary-color)] pr-3">
{{ (item.bookCount$ | async)?.toString() || '0' }}
</p>
{{ (item.bookCount$ | async)?.toString() || '0' }}
</p>
}
</span>
</span>
</div>
<div [@children]="isExpanded(key) ? 'expanded' : 'collapsed'" style="overflow: hidden;">
@@ -1,4 +1,4 @@
import {Component, HostBinding, Input, OnDestroy, OnInit} from '@angular/core';
import {Component, ElementRef, HostBinding, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {NavigationEnd, Router, RouterLink, RouterLinkActive} from '@angular/router';
import {animate, state, style, transition, trigger} from '@angular/animations';
import {Subscription} from 'rxjs';
@@ -41,38 +41,30 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
@Input() index!: number;
@Input() @HostBinding('class.layout-root-menuitem') root!: boolean;
@Input() parentKey!: string;
@ViewChild('linkRef') linkRef!: ElementRef<HTMLAnchorElement>;
hovered = false;
active = false;
key: string = "";
canManipulateLibrary: boolean = false;
admin: boolean = false;
expandedItems = new Set<string>();
menuSourceSubscription: Subscription;
menuResetSubscription: Subscription;
expandedItems = new Set<string>();
toggleExpand(key: string) {
if (this.expandedItems.has(key)) {
this.expandedItems.delete(key);
} else {
this.expandedItems.add(key);
}
}
isExpanded(key: string): boolean {
return this.expandedItems.has(key);
}
constructor(public router: Router, private menuService: MenuService, private userService: UserService, private dialogLauncher: DialogLauncherService) {
constructor(
public router: Router,
private menuService: MenuService,
private userService: UserService,
private dialogLauncher: DialogLauncherService
) {
this.userService.userState$.subscribe(userState => {
if (userState?.user) {
this.canManipulateLibrary = userState.user.permissions.canManipulateLibrary;
this.admin = userState.user.permissions.admin;
}
});
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
Promise.resolve(null).then(() => {
if (value.routeEvent) {
@@ -105,6 +97,27 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
}
}
ngOnDestroy() {
if (this.menuSourceSubscription) {
this.menuSourceSubscription.unsubscribe();
}
if (this.menuResetSubscription) {
this.menuResetSubscription.unsubscribe();
}
}
toggleExpand(key: string) {
if (this.expandedItems.has(key)) {
this.expandedItems.delete(key);
} else {
this.expandedItems.add(key);
}
}
isExpanded(key: string): boolean {
return this.expandedItems.has(key);
}
updateActiveStateFromRoute() {
const activeRoute = this.router.isActive(this.item.routerLink[0], {
paths: 'exact',
@@ -131,20 +144,6 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
this.menuService.onMenuStateChange({key: this.key});
}
@HostBinding('class.active-menuitem')
get activeClass() {
return this.active && !this.root;
}
ngOnDestroy() {
if (this.menuSourceSubscription) {
this.menuSourceSubscription.unsubscribe();
}
if (this.menuResetSubscription) {
this.menuResetSubscription.unsubscribe();
}
}
openDialog(item: any) {
if (item.type === 'library' && this.canManipulateLibrary) {
this.dialogLauncher.openLibraryCreatorDialog();
@@ -153,4 +152,15 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
this.dialogLauncher.openMagicShelfDialog();
}
}
triggerLink() {
if (this.item.routerLink && !this.item.items && this.linkRef) {
this.linkRef.nativeElement.click();
}
}
@HostBinding('class.active-menuitem')
get activeClass() {
return this.active && !this.root;
}
}