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

TabMenu: Highlight does not update when selecting routerLink to unloaded module #15012

Closed
dcbroad3 opened this issue Mar 11, 2024 · 2 comments · Fixed by #15819 · 4 remaining pull requests
Closed

TabMenu: Highlight does not update when selecting routerLink to unloaded module #15012

dcbroad3 opened this issue Mar 11, 2024 · 2 comments · Fixed by #15819 · 4 remaining pull requests
Assignees
Labels
LTS-PORTABLE PRO Support Issue was reported by PRO User Type: Bug Issue contains a bug related to a specific component. Something about the component is not working v18-port
Milestone

Comments

@dcbroad3
Copy link
Contributor

dcbroad3 commented Mar 11, 2024

Describe the bug

When using the TabMenu with options that open router links to standalone components / lazy loaded modules, the active menu item is not updated when you click on those options for the first time (since they have not been loaded yet).

Note: This only seems to be an issue when using a custom item template.

The issue seems to be that the isActive function in the TabMenu template checks the router state at the time change detection is run, but since the route has not been loaded when that function is called, it does not match. Later, when the route is finished updating, the component is not checked again because the change detection strategy is OnPush. If change detection is run manually, the highlighed option is correctly updated.

Environment

See StackBlitz example. Angular 17.2.x, PrimeNG 17.10.x

Reproducer

https://stackblitz.com/edit/wrtgnz?file=src%2Fapp%2Fdemo%2Ftab-menu-basic-demo.html

Angular version

17.2

PrimeNG version

17.10

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

18.18

Browser(s)

No response

Steps to reproduce the behavior

In stackblitz link:

  1. Note that the initial route does not get highlighted when you first load the application
  2. Click "Home", it will be highlighted
  3. Click "Calendar", it will navigate but not highlight
  4. Click "Calendar" again, it will highlight

Expected behavior

No response

@dcbroad3 dcbroad3 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Mar 11, 2024
@dcbroad3 dcbroad3 changed the title TabMenu: Active option does not updating when selecting routerLink to module that has not been loaded yet TabMenu: Active option does not update when selecting routerLink to module that has not been loaded yet Mar 11, 2024
@dcbroad3 dcbroad3 changed the title TabMenu: Active option does not update when selecting routerLink to module that has not been loaded yet TabMenu: Highlight does not update when selecting routerLink to unloaded module Mar 11, 2024
@dcbroad3
Copy link
Contributor Author

Side note: This issue did not appear with Angular 16 / PrimeNG 16. I assume this is not a regression in PrimeNG but rather due to a change in behavior in Angular 17, because it doesn't seem this module has undergone significant changes for v17.

@dcbroad3
Copy link
Contributor Author

I was using the custom item templates to enable runtime translations. I can instead use an observable for the items, generating a new list of tab menu items any time the language changes, and then remove the custom item template, and that serves as a workaround.

I have also found an acceptable workaround is to add a click handler on the custom item template, watch for one NavigationEnd event in the router.events observable, and then call markForCheck on the tabmenu.

@mehmetcetin01140 mehmetcetin01140 added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Mar 18, 2024
@mehmetcetin01140 mehmetcetin01140 added this to the 17.18.1 milestone Jun 11, 2024
@mehmetcetin01140 mehmetcetin01140 self-assigned this Jun 11, 2024
@mehmetcetin01140 mehmetcetin01140 added the PRO Support Issue was reported by PRO User label Jun 11, 2024
@cetincakiroglu cetincakiroglu modified the milestones: 17.18.1, 17.18.2 Jun 13, 2024
cetincakiroglu added a commit that referenced this issue Jun 27, 2024
Fixed #15012 - TabMenu: Highlight does not update when selecting rout…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment