From f69b3cf871da4a691864351aac3e7ba18d1b23fd Mon Sep 17 00:00:00 2001 From: louis-19041904 Date: Mon, 17 Aug 2026 20:23:48 +0200 Subject: [PATCH 1/5] fix(tooltip): don't close a tooltip while a nested tooltip inside it is open --- .../directives/component-tooltip.directive.ts | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/webapp/src/app/directives/component-tooltip.directive.ts b/webapp/src/app/directives/component-tooltip.directive.ts index 2f9e8735..7fc7d482 100644 --- a/webapp/src/app/directives/component-tooltip.directive.ts +++ b/webapp/src/app/directives/component-tooltip.directive.ts @@ -27,6 +27,10 @@ type UnwrapInputSignals = { standalone: true, }) export class ComponentTooltipDirective implements OnDestroy { + private static readonly openInstances = new Set< + ComponentTooltipDirective + >(); + readonly component = input.required>({ alias: 'appComponentTooltip', }); @@ -104,13 +108,32 @@ export class ComponentTooltipDirective implements OnDestroy { } private scheduleHide(): void { + clearTimeout(this.hideTimeout); this.hideTimeout = setTimeout(() => { - if (!this.isOverHost && !this.isOverOverlay) { - this.hide(); + if (this.isOverHost || this.isOverOverlay) { + return; } + if (this.hasOpenDescendantTooltip()) { + this.scheduleHide(); + return; + } + this.hide(); }, this.tooltipHideDelay()); } + private hasOpenDescendantTooltip(): boolean { + const paneElement = this.overlayRef?.overlayElement; + if (!paneElement) return false; + + for (const other of ComponentTooltipDirective.openInstances) { + if (other === this) continue; + if (paneElement.contains(other.elementRef.nativeElement)) { + return true; + } + } + return false; + } + private show(): void { if (this.overlayRef?.hasAttached()) return; @@ -175,6 +198,8 @@ export class ComponentTooltipDirective implements OnDestroy { overlayElement.addEventListener('mouseenter', this.onOverlayEnter); overlayElement.addEventListener('mouseleave', this.onOverlayLeave); overlayElement.addEventListener('click', this.onOverlayClick, true); + + ComponentTooltipDirective.openInstances.add(this); } private applyMaxWidth( @@ -212,12 +237,14 @@ export class ComponentTooltipDirective implements OnDestroy { this.overlayRef.detach(); } this.componentRef = null; + ComponentTooltipDirective.openInstances.delete(this); } ngOnDestroy(): void { clearTimeout(this.showTimeout); clearTimeout(this.hideTimeout); clearTimeout(this.dismissTimeout); + ComponentTooltipDirective.openInstances.delete(this); this.overlayRef?.dispose(); } } -- 2.56.1 From 8261de4a0228ca62d4e51d0da3022c4ec018ddc1 Mon Sep 17 00:00:00 2001 From: louis-19041904 Date: Mon, 17 Aug 2026 21:44:55 +0200 Subject: [PATCH 2/5] fix(tooltip): prevent tooltips from clipping off-screen near edges --- .../directives/component-tooltip.directive.ts | 186 ++++++++++++++---- webapp/src/styles.scss | 5 + 2 files changed, 154 insertions(+), 37 deletions(-) diff --git a/webapp/src/app/directives/component-tooltip.directive.ts b/webapp/src/app/directives/component-tooltip.directive.ts index 7fc7d482..8bd50ceb 100644 --- a/webapp/src/app/directives/component-tooltip.directive.ts +++ b/webapp/src/app/directives/component-tooltip.directive.ts @@ -18,6 +18,12 @@ import { } from '@angular/cdk/overlay'; import { ComponentPortal, ComponentType } from '@angular/cdk/portal'; +const STICKY_TOOLBAR_HEIGHT_PX = 76; +const EDGE_MARGIN_PX = 8; +const TOP_MARGIN_PX = STICKY_TOOLBAR_HEIGHT_PX + EDGE_MARGIN_PX; +const MIN_PANEL_WIDTH_PX = 240; +const MIN_PANEL_HEIGHT_PX = 150; + type UnwrapInputSignals = { [K in keyof T]: T[K] extends InputSignal ? V : T[K]; }; @@ -47,6 +53,7 @@ export class ComponentTooltipDirective implements OnDestroy { private overlayRef: OverlayRef | null = null; private componentRef: ComponentRef | null = null; + private computedMaxWidthPx = MIN_PANEL_WIDTH_PX; private showTimeout?: ReturnType; private hideTimeout?: ReturnType; private dismissTimeout?: ReturnType; @@ -134,52 +141,143 @@ export class ComponentTooltipDirective implements OnDestroy { return false; } + private clampedOffsetX( + alignToStart: boolean, + triggerRect: DOMRect, + actualWidthPx: number, + viewportWidth: number, + ): number { + const desiredLeft = alignToStart + ? triggerRect.left + : triggerRect.right - actualWidthPx; + const minLeft = EDGE_MARGIN_PX; + const maxLeft = Math.max( + EDGE_MARGIN_PX, + viewportWidth - actualWidthPx - EDGE_MARGIN_PX, + ); + const clampedLeft = Math.min(Math.max(desiredLeft, minLeft), maxLeft); + const anchor = alignToStart ? triggerRect.left : triggerRect.right; + return clampedLeft - anchor + (alignToStart ? 0 : actualWidthPx); + } + + private computePositioning(): { + positions: ConnectedPosition[]; + maxWidthPx: number; + maxHeightPx: number; + } { + const triggerRect = this.elementRef.nativeElement.getBoundingClientRect(); + const viewportWidth = window.innerWidth; + const viewportHeight = window.innerHeight; + + const spaceAbove = triggerRect.top - TOP_MARGIN_PX; + const spaceBelow = viewportHeight - triggerRect.bottom - EDGE_MARGIN_PX; + const spaceLeft = triggerRect.left - EDGE_MARGIN_PX; + const spaceRight = viewportWidth - triggerRect.right - EDGE_MARGIN_PX; + + const preferBelow = spaceBelow >= spaceAbove; + const preferStartAligned = spaceRight >= spaceLeft; + + const bestVerticalSpace = Math.max(spaceAbove, spaceBelow); + const bestHorizontalSpace = Math.max(spaceLeft, spaceRight); + + const maxHeightPx = Math.max(bestVerticalSpace, MIN_PANEL_HEIGHT_PX); + const maxWidthPx = Math.max(bestHorizontalSpace, MIN_PANEL_WIDTH_PX); + const actualWidthPx = Math.min( + maxWidthPx, + this.resolveConfiguredWidthPx(this.tooltipMaxWidth()) ?? maxWidthPx, + ); + + const primaryOffsetX = this.clampedOffsetX( + preferStartAligned, + triggerRect, + actualWidthPx, + viewportWidth, + ); + const secondaryOffsetX = this.clampedOffsetX( + !preferStartAligned, + triggerRect, + actualWidthPx, + viewportWidth, + ); + + const verticalPrimary: ConnectedPosition = preferBelow + ? { + originX: preferStartAligned ? 'start' : 'end', + originY: 'bottom', + overlayX: preferStartAligned ? 'start' : 'end', + overlayY: 'top', + offsetX: primaryOffsetX, + offsetY: EDGE_MARGIN_PX, + } + : { + originX: preferStartAligned ? 'start' : 'end', + originY: 'top', + overlayX: preferStartAligned ? 'start' : 'end', + overlayY: 'bottom', + offsetX: primaryOffsetX, + offsetY: -EDGE_MARGIN_PX, + }; + const verticalSecondary: ConnectedPosition = preferBelow + ? { + originX: preferStartAligned ? 'end' : 'start', + originY: 'top', + overlayX: preferStartAligned ? 'end' : 'start', + overlayY: 'bottom', + offsetX: secondaryOffsetX, + offsetY: -EDGE_MARGIN_PX, + } + : { + originX: preferStartAligned ? 'end' : 'start', + originY: 'bottom', + overlayX: preferStartAligned ? 'end' : 'start', + overlayY: 'top', + offsetX: secondaryOffsetX, + offsetY: EDGE_MARGIN_PX, + }; + const sidePrimary: ConnectedPosition = preferStartAligned + ? { + originX: 'end', + originY: 'center', + overlayX: 'start', + overlayY: 'center', + offsetX: EDGE_MARGIN_PX, + } + : { + originX: 'start', + originY: 'center', + overlayX: 'end', + overlayY: 'center', + offsetX: -EDGE_MARGIN_PX, + }; + + const positions: ConnectedPosition[] = [ + verticalPrimary, + verticalSecondary, + sidePrimary, + ]; + + return { positions, maxWidthPx, maxHeightPx }; + } + private show(): void { if (this.overlayRef?.hasAttached()) return; - const positions: ConnectedPosition[] = [ - { - originX: 'center', - originY: 'top', - overlayX: 'center', - overlayY: 'bottom', - offsetY: -8, - }, - { - originX: 'center', - originY: 'bottom', - overlayX: 'center', - overlayY: 'top', - offsetY: 8, - }, - { - originX: 'end', - originY: 'center', - overlayX: 'start', - overlayY: 'center', - offsetX: 8, - }, - { - originX: 'start', - originY: 'center', - overlayX: 'end', - overlayY: 'center', - offsetX: -8, - }, - ]; + const { positions, maxWidthPx, maxHeightPx } = this.computePositioning(); + this.computedMaxWidthPx = maxWidthPx; const positionStrategy = this.overlayPositionBuilder .flexibleConnectedTo(this.elementRef) .withPositions(positions) .withFlexibleDimensions(false) - .withViewportMargin(12) + .withViewportMargin(EDGE_MARGIN_PX) .withPush(true); this.overlayRef = this.overlay.create({ positionStrategy, scrollStrategy: this.overlay.scrollStrategies.reposition(), panelClass: 'app-tooltip-panel', - maxWidth: this.tooltipMaxWidth() ?? 'calc(100vw - 24px)', + maxWidth: this.resolveMaxWidth(this.tooltipMaxWidth()), + maxHeight: `${maxHeightPx}px`, }); const portal = new ComponentPortal(this.component(), null, this.injector); @@ -206,12 +304,26 @@ export class ComponentTooltipDirective implements OnDestroy { element: HTMLElement, maxWidth: string | number | null, ): void { - if (maxWidth === null) { - element.style.maxWidth = ''; - return; + element.style.maxWidth = this.resolveMaxWidth(maxWidth); + } + + private resolveMaxWidth(maxWidth: string | number | null): string { + const configuredPx = this.resolveConfiguredWidthPx(maxWidth); + if (configuredPx === null) { + return typeof maxWidth === 'number' + ? `${maxWidth}px` + : (maxWidth ?? `${this.computedMaxWidthPx}px`); } - element.style.maxWidth = - typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth; + return `${Math.min(configuredPx, this.computedMaxWidthPx)}px`; + } + + private resolveConfiguredWidthPx( + maxWidth: string | number | null, + ): number | null { + if (maxWidth === null) return null; + if (typeof maxWidth === 'number') return maxWidth; + const trimmed = maxWidth.trim(); + return trimmed.endsWith('px') ? parseFloat(trimmed) : null; } private readonly onOverlayEnter = (): void => { diff --git a/webapp/src/styles.scss b/webapp/src/styles.scss index 14690546..86fde541 100644 --- a/webapp/src/styles.scss +++ b/webapp/src/styles.scss @@ -582,6 +582,11 @@ html.dark-theme { line-height: 1.4; } +.cdk-overlay-pane.app-tooltip-panel { + max-height: 70vh; + overflow: auto; +} + .cdk-overlay-pane .mat-mdc-option { padding: 0 18px; font-size: 13px; -- 2.56.1 From ac97c9f49652470bc12024e3e950538aed346c60 Mon Sep 17 00:00:00 2001 From: louis-19041904 Date: Mon, 17 Aug 2026 22:02:58 +0200 Subject: [PATCH 3/5] fix(publication-card): cap tooltip width, size topics to content, truncate chip labels --- .../modules/dashboard/dashboard.component.html | 1 + .../institution-patents.component.html | 3 ++- .../person-network/person-network.component.html | 12 ++++++++---- .../app-author-chip.component.html | 3 ++- .../app-author-chip.component.scss | 16 ++++++++++++++++ .../app-institution-chip.component.html | 1 + .../app-publication-card.component.html | 4 +++- .../app-publication-card.component.scss | 4 ++++ .../app-publication-card.component.ts | 1 + .../app-publication-tooltip.component.html | 2 +- .../app-topic-chip/app-topic-chip.component.html | 2 +- .../app-topic-chip/app-topic-chip.component.scss | 16 ++++++++++++++++ .../ui/patent-table/patent-table.component.html | 1 + 13 files changed, 57 insertions(+), 9 deletions(-) diff --git a/webapp/src/app/modules/dashboard/dashboard.component.html b/webapp/src/app/modules/dashboard/dashboard.component.html index e2823c5b..73d21e66 100644 --- a/webapp/src/app/modules/dashboard/dashboard.component.html +++ b/webapp/src/app/modules/dashboard/dashboard.component.html @@ -455,6 +455,7 @@ [queryParams]="authorQueryParams(dataset, entry)" [appComponentTooltip]="AuthorTooltipComponent" [tooltipInputs]="{ authorId: entry.id }" + [tooltipMaxWidth]="'500px'" [title]="authorDisplayName(dataset, entry)"> {{ authorDisplayName(dataset, entry) }} diff --git a/webapp/src/app/modules/institution-patents/institution-patents.component.html b/webapp/src/app/modules/institution-patents/institution-patents.component.html index e6b144f0..68d414a6 100644 --- a/webapp/src/app/modules/institution-patents/institution-patents.component.html +++ b/webapp/src/app/modules/institution-patents/institution-patents.component.html @@ -141,7 +141,8 @@ [appComponentTooltip]="AuthorTooltipComponent" [tooltipInputs]="{ authorId: author.openalex_author_id, - }"> + }" + [tooltipMaxWidth]="'500px'"> {{ author.author_name }} diff --git a/webapp/src/app/modules/person-network/person-network.component.html b/webapp/src/app/modules/person-network/person-network.component.html index e17a31e0..95c46d87 100644 --- a/webapp/src/app/modules/person-network/person-network.component.html +++ b/webapp/src/app/modules/person-network/person-network.component.html @@ -131,7 +131,8 @@ [appComponentTooltip]="AppPublicationTooltipComponent" [tooltipInputs]="{ workId: this.stripOpenAlexIdPrefix(work.id), - }"> + }" + [tooltipMaxWidth]="'500px'">
  • {{ work.display_name }}
  • } @@ -150,7 +151,8 @@ [appComponentTooltip]="AppInstitutionTooltipComponent" [tooltipInputs]="{ institutionId: this.stripOpenAlexIdPrefix(institution.id), - }"> + }" + [tooltipMaxWidth]="'500px'">
  • {{ institution.display_name }}
  • } @@ -188,7 +190,8 @@ [appComponentTooltip]="AppAuthorTooltipComponent" [tooltipInputs]="{ authorId: this.stripOpenAlexIdPrefix(collaborator.id), - }"> + }" + [tooltipMaxWidth]="'500px'"> {{ collaborator.display_name }} @@ -227,7 +230,8 @@ [appComponentTooltip]="AppAuthorTooltipComponent" [tooltipInputs]="{ authorId: this.stripOpenAlexIdPrefix(collaborator.id), - }"> + }" + [tooltipMaxWidth]="'500px'"> {{ collaborator.display_name }} diff --git a/webapp/src/app/shared/ui/app-author-chip/app-author-chip.component.html b/webapp/src/app/shared/ui/app-author-chip/app-author-chip.component.html index 9bf69e9f..72c12e13 100644 --- a/webapp/src/app/shared/ui/app-author-chip/app-author-chip.component.html +++ b/webapp/src/app/shared/ui/app-author-chip/app-author-chip.component.html @@ -2,12 +2,13 @@ class="author-chip" [appComponentTooltip]="AuthorTooltipComponent" [tooltipInputs]="{ author: _author(), authorId: rawOaAuthorId() }" + [tooltipMaxWidth]="'500px'" (keydown)="_onChipClick($event)" (click)="_onChipClick($event)"> @if (showIcon()) { {{ icon() }} } - {{ _author()?.display_name }} + {{ _author()?.display_name }} diff --git a/webapp/src/app/shared/ui/app-author-chip/app-author-chip.component.scss b/webapp/src/app/shared/ui/app-author-chip/app-author-chip.component.scss index 931c7aa8..43816c84 100644 --- a/webapp/src/app/shared/ui/app-author-chip/app-author-chip.component.scss +++ b/webapp/src/app/shared/ui/app-author-chip/app-author-chip.component.scss @@ -1,8 +1,16 @@ +:host { + display: inline-flex; + min-width: 0; + max-width: 100%; +} + .author-chip { font-weight: 500; border-radius: var(--sg-radius-sm); background-color: var(--sg-surface-soft); border: var(--border-width) solid var(--border-color); + max-width: 100%; + min-width: 0; } :host ::ng-deep .author-chip .mat-mdc-chip-action, @@ -29,6 +37,7 @@ display: flex; align-items: center; gap: 0.5rem; + min-width: 0; color: var(--sg-text); mat-icon { @@ -36,6 +45,13 @@ } } +.chip-label { + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + min-width: 0; +} + :host.is-mini-size { ::ng-deep .mat-mdc-chip { height: 1.5rem; diff --git a/webapp/src/app/shared/ui/app-institution-chip/app-institution-chip.component.html b/webapp/src/app/shared/ui/app-institution-chip/app-institution-chip.component.html index 17139d66..d1526086 100644 --- a/webapp/src/app/shared/ui/app-institution-chip/app-institution-chip.component.html +++ b/webapp/src/app/shared/ui/app-institution-chip/app-institution-chip.component.html @@ -5,6 +5,7 @@ institution: _institution(), institutionId: rawOaInstitutionId(), }" + [tooltipMaxWidth]="'500px'" (keydown)="_onChipClick($event)" (click)="_onChipClick($event)"> diff --git a/webapp/src/app/shared/ui/app-publication-card/app-publication-card.component.html b/webapp/src/app/shared/ui/app-publication-card/app-publication-card.component.html index ddda118a..30620ed6 100644 --- a/webapp/src/app/shared/ui/app-publication-card/app-publication-card.component.html +++ b/webapp/src/app/shared/ui/app-publication-card/app-publication-card.component.html @@ -17,7 +17,9 @@ label Themen -
    +
    @for (topic of visibleTopics(); track topic.id) { (); + sizeTopicsToContent = input(false); topicChipClick = output(); authorChipClick = output(); diff --git a/webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.html b/webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.html index 7d134a10..1644810e 100644 --- a/webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.html +++ b/webapp/src/app/shared/ui/app-publication-tooltip/app-publication-tooltip.component.html @@ -1,5 +1,5 @@ @let work = this._work(); @if (work) { - + } diff --git a/webapp/src/app/shared/ui/app-topic-chip/app-topic-chip.component.html b/webapp/src/app/shared/ui/app-topic-chip/app-topic-chip.component.html index 7dea292f..f07d20af 100644 --- a/webapp/src/app/shared/ui/app-topic-chip/app-topic-chip.component.html +++ b/webapp/src/app/shared/ui/app-topic-chip/app-topic-chip.component.html @@ -9,6 +9,6 @@ @if (showIcon()) { {{ icon() }} } - {{ topic().display_name }} + {{ topic().display_name }} diff --git a/webapp/src/app/shared/ui/app-topic-chip/app-topic-chip.component.scss b/webapp/src/app/shared/ui/app-topic-chip/app-topic-chip.component.scss index 3b34d81c..974feea4 100644 --- a/webapp/src/app/shared/ui/app-topic-chip/app-topic-chip.component.scss +++ b/webapp/src/app/shared/ui/app-topic-chip/app-topic-chip.component.scss @@ -1,3 +1,9 @@ +:host { + display: inline-flex; + min-width: 0; + max-width: 100%; +} + .topic-chip { --topic-background: color-mix( in srgb, @@ -20,6 +26,8 @@ align-items: center; gap: 0.5rem; color: var(--sg-text); + max-width: 100%; + min-width: 0; } :host ::ng-deep .topic-chip .mat-mdc-chip-action, @@ -54,6 +62,7 @@ display: flex; align-items: center; gap: 0.5rem; + min-width: 0; color: var(--sg-text); mat-icon { @@ -61,6 +70,13 @@ } } +.chip-label { + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + min-width: 0; +} + :host.is-mini-size { ::ng-deep .mat-mdc-chip { height: 1.5rem; diff --git a/webapp/src/app/shared/ui/patent-table/patent-table.component.html b/webapp/src/app/shared/ui/patent-table/patent-table.component.html index 0a6fcdae..b9478e5e 100644 --- a/webapp/src/app/shared/ui/patent-table/patent-table.component.html +++ b/webapp/src/app/shared/ui/patent-table/patent-table.component.html @@ -104,6 +104,7 @@ [routerLink]="['/person', author.openalex_author_id]" [appComponentTooltip]="AuthorTooltipComponent" [tooltipInputs]="{ authorId: author.openalex_author_id }" + [tooltipMaxWidth]="'500px'" (click)="$event.stopPropagation()"> {{ author.author_name }} -- 2.56.1 From 0f9991b618414ee8bdac64a8a7440266e4386688 Mon Sep 17 00:00:00 2001 From: louis-19041904 Date: Mon, 17 Aug 2026 22:08:52 +0200 Subject: [PATCH 4/5] feat(institution-card): show country flag next to city/country subtitle --- .../app-institution-card.component.html | 15 +++++++++++---- .../app-institution-card.component.ts | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/webapp/src/app/shared/ui/app-institution-card/app-institution-card.component.html b/webapp/src/app/shared/ui/app-institution-card/app-institution-card.component.html index d10b5858..7abfe32c 100644 --- a/webapp/src/app/shared/ui/app-institution-card/app-institution-card.component.html +++ b/webapp/src/app/shared/ui/app-institution-card/app-institution-card.component.html @@ -8,10 +8,17 @@ "> {{ displayName() }} - {{ institution().geo?.city }}, - {{ institution().geo?.country }} + + {{ institution().geo?.city }}, + {{ institution().geo?.country }} + @if (institution().geo?.country_code) { + + } + diff --git a/webapp/src/app/shared/ui/app-institution-card/app-institution-card.component.ts b/webapp/src/app/shared/ui/app-institution-card/app-institution-card.component.ts index 8b92a5b4..0f1db8cf 100644 --- a/webapp/src/app/shared/ui/app-institution-card/app-institution-card.component.ts +++ b/webapp/src/app/shared/ui/app-institution-card/app-institution-card.component.ts @@ -15,6 +15,7 @@ import { MatIconModule } from '@angular/material/icon'; import { MatButtonModule } from '@angular/material/button'; import { DecimalPipe } from '@angular/common'; import { CredentialService } from '../../services/credential.service'; +import { CountryFlagComponent } from '../country-flag/country-flag.component'; @Component({ selector: 'app-institution-card', @@ -25,6 +26,7 @@ import { CredentialService } from '../../services/credential.service'; MatIconModule, MatButtonModule, DecimalPipe, + CountryFlagComponent, ], templateUrl: './app-institution-card.component.html', styleUrl: './app-institution-card.component.scss', -- 2.56.1 From e7b6255e540cb34177a5014d990e64668e92d4a0 Mon Sep 17 00:00:00 2001 From: louis-19041904 Date: Mon, 17 Aug 2026 22:20:43 +0200 Subject: [PATCH 5/5] fix(sidebar): highlight nav item for detail pages, not just their list route --- .../ui/app-menu/app-menu.component.html | 6 +-- .../shared/ui/app-menu/app-menu.component.ts | 41 ++++++++++++++----- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/webapp/src/app/shared/ui/app-menu/app-menu.component.html b/webapp/src/app/shared/ui/app-menu/app-menu.component.html index 5bcd72ff..8771e738 100644 --- a/webapp/src/app/shared/ui/app-menu/app-menu.component.html +++ b/webapp/src/app/shared/ui/app-menu/app-menu.component.html @@ -67,8 +67,7 @@ class="nav-icon-button" [routerLink]="item.disabled ? null : item.route" [queryParams]="item.queryParams || null" - routerLinkActive="active" - [routerLinkActiveOptions]="navLinkActiveOptions" + [class.active]="isItemActive(item)" [class.disabled]="item.disabled" [matTooltip]="item.label" matTooltipPosition="right" @@ -80,8 +79,7 @@ mat-list-item [routerLink]="item.disabled ? null : item.route" [queryParams]="item.queryParams || null" - routerLinkActive="active" - [routerLinkActiveOptions]="navLinkActiveOptions" + [class.active]="isItemActive(item)" [class.disabled]="item.disabled"> {{ item.icon }} {{ item.label }} diff --git a/webapp/src/app/shared/ui/app-menu/app-menu.component.ts b/webapp/src/app/shared/ui/app-menu/app-menu.component.ts index 40d4bfb6..d41bcc09 100644 --- a/webapp/src/app/shared/ui/app-menu/app-menu.component.ts +++ b/webapp/src/app/shared/ui/app-menu/app-menu.component.ts @@ -1,6 +1,8 @@ import { Component, computed, inject, input, output } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { IsActiveMatchOptions, Router, RouterModule } from '@angular/router'; +import { NavigationEnd, Router, RouterModule } from '@angular/router'; +import { toSignal } from '@angular/core/rxjs-interop'; +import { filter, map } from 'rxjs'; import { MatIconModule } from '@angular/material/icon'; import { MatListModule } from '@angular/material/list'; import { MatButtonModule } from '@angular/material/button'; @@ -42,6 +44,7 @@ type NavItem = { adminOnly?: boolean; superAdminOnly?: boolean; managerOrAdminOnly?: boolean; + detailRoutePrefixes?: string[]; }; type NavItemGroup = { @@ -75,12 +78,26 @@ export class AppMenuComponent { collapsed = input(false); canCollapse = input(false); toggleCollapsed = output(); - readonly navLinkActiveOptions: IsActiveMatchOptions = { - paths: 'subset', - queryParams: 'ignored', - matrixParams: 'ignored', - fragment: 'ignored', - }; + + private readonly router = inject(Router); + + private readonly currentPath = toSignal( + this.router.events.pipe( + filter((event): event is NavigationEnd => event instanceof NavigationEnd), + map((event) => event.urlAfterRedirects.split('?')[0]), + ), + { initialValue: this.router.url.split('?')[0] }, + ); + + isItemActive(item: NavItem): boolean { + const path = this.currentPath(); + if (path === item.route || path.startsWith(`${item.route}/`)) { + return true; + } + return (item.detailRoutePrefixes ?? []).some((prefix) => + path.startsWith(prefix), + ); + } readonly navItems = computed(() => { const items: NavItem[] = [ @@ -99,6 +116,7 @@ export class AppMenuComponent { this.credentialService.organizationName(), ), disabled: false, + detailRoutePrefixes: ['/person/'], }, { label: 'Bookmarks', @@ -124,6 +142,7 @@ export class AppMenuComponent { sort_by: 'works_count', sorting_order: SortDirection.Desc, }, + detailRoutePrefixes: ['/institution/'], }, { label: 'Publikationen', @@ -137,6 +156,7 @@ export class AppMenuComponent { [workQueryParamKeys.sortBy]: WorkSortBy.CitedByCount, [workQueryParamKeys.sortDirection]: SortDirection.Desc, }, + detailRoutePrefixes: ['/publication/'], }, { label: 'Themen', @@ -150,6 +170,7 @@ export class AppMenuComponent { [topicQueryParamKeys.sortBy]: TopicSortBy.CitedByCount, [topicQueryParamKeys.sortDirection]: SortDirection.Desc, }, + detailRoutePrefixes: ['/topic/'], }, { label: 'Projekte', @@ -170,6 +191,7 @@ export class AppMenuComponent { icon: PATENT_ICON, route: '/patents', disabled: false, + detailRoutePrefixes: ['/patent/'], }, { label: 'Keywords', @@ -230,10 +252,7 @@ export class AppMenuComponent { ]; }); - constructor( - public credentialService: CredentialService, - private readonly router: Router, - ) {} + constructor(public credentialService: CredentialService) {} isNavigating = computed(() => !!this.router.currentNavigation()); readonly themeService = inject(ThemeService); -- 2.56.1