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

PanelMenu - Repeating menu items #15796

Open
jalley3 opened this issue Jun 5, 2024 · 8 comments
Open

PanelMenu - Repeating menu items #15796

jalley3 opened this issue Jun 5, 2024 · 8 comments
Labels
Resolution: Needs More Information More information about the issue is needed to find a correct solution
Milestone

Comments

@jalley3
Copy link

jalley3 commented Jun 5, 2024

Describe the bug

#14373 ... basically this bug is back... see my comment at the end for current pictures ...note this is working in 17.16

Environment

version 17.17 and 17.18

Reproducer

No response

Angular version

17.3.4

PrimeNG version

17.17

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20.10

Browser(s)

No response

Steps to reproduce the behavior

image

Expected behavior

image

@jalley3 jalley3 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jun 5, 2024
@jalley3
Copy link
Author

jalley3 commented Jun 5, 2024

@mehmetcetin01140 i believe it is related to your changes

@guaido79
Copy link

guaido79 commented Jun 5, 2024

I found thats uncommon behavior too.
I see it's due to the routerLink in the MenuItem. If you remove it it come back to single menu per item.
To fix my code i add another property in the any property of MenuItem and bind it in the menu template.

@jalley3
Copy link
Author

jalley3 commented Jun 5, 2024

remove the routerlink? those are supposed to be links to other pages so i need the router links @guaido79

@guaido79
Copy link

guaido79 commented Jun 5, 2024

remove the routerlink? those are supposed to be links to other pages so i need the router links @guaido79

Yes, sure, I give just some more information to find the problem.

in the example of the showcase on Stackblitz routerLink it's not used:

items: MenuItem[];

    constructor(private router: Router) {}

    ngOnInit() {
        this.items = [
            {
                label: 'Router',
                icon: 'pi pi-palette',
                items: [
                    {
                        label: 'Installation',
                        icon: 'pi pi-eraser',
                        route: '/installation'
                    },
                    {
                        label: 'Configuration',
                        icon: 'pi pi-heart',
                        route: '/configuration'
                    }
                ]
            },
            {
                label: 'Programmatic',
                icon: 'pi pi-link',
                command: () => {
                    this.router.navigate(['/installation']);
                }
            },
<p-panelMenu [model]="items" styleClass="w-full md:w-20rem">
        <ng-template pTemplate="item" let-item>
            <ng-container *ngIf="item.route; else urlRef">
                <a [routerLink]="item.route" class="flex align-items-center 
                    cursor-pointer text-color px-3 py-2">
                    <span [class]="item.icon"></span>
                    <span class="ml-2 text-color">{{ item.label }}</span>
                </a>
            </ng-container>

@jalley3
Copy link
Author

jalley3 commented Jun 6, 2024

@guaido79 thank you however MenuItem does not even contain a route property (https://primeng.org/dock#api.dock.interfaces.MenuItem ) which breaks a lot of our strongly typed methods and means redoing our entire site's navigation that is currently set up to use RouterLink in the MenuItem. Its frustrating because it just worked in v17.16

@mehmetcetin01140 mehmetcetin01140 added this to the 17.18.1 milestone Jun 6, 2024
@cetincakiroglu cetincakiroglu modified the milestones: 17.18.1, 17.18.2 Jun 13, 2024
@mehmetcetin01140 mehmetcetin01140 modified the milestones: 17.18.2, 17.18.3 Jun 27, 2024
@cetincakiroglu
Copy link
Contributor

Hi @jalley3 ,

Could you please share a stackblitz reproducer?

@cetincakiroglu cetincakiroglu added Resolution: Needs More Information More information about the issue is needed to find a correct solution and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Jul 4, 2024
@cetincakiroglu cetincakiroglu modified the milestones: 17.18.3, 17.18.4 Jul 4, 2024
@mehmetcetin01140 mehmetcetin01140 modified the milestones: 17.18.4, 17.18.5, 17.18.6 Jul 11, 2024
@SippieCup
Copy link

SippieCup commented Oct 31, 2024

Reproduction on v18:
https://stackblitz.com/~/github.com/SippieCup/panelMenu-duplication

Edit: its due to rendering the panel header, then seeing the item template, and rendering the item template as well. rather than skipping the panel header or the item itself when rendering on root items.

you can pass a boolean into item.state.isRoot and just check that in the template, and not render anything

  <ng-template pTemplate="item" let-item>
    @if (!item.state?.root) {
      @if (item.routerLink) {

      <a [routerLink]="item.routerLink" class="flex align-items-center
                cursor-pointer  px-3 py-2 group">
        <span [class]="item.icon"></span>
        <span class="ml-2">{{ item.label }}</span>
      </a>
      } @else if (item.url){

      <a [href]="item.url" class="flex align-items-center
                cursor-pointer text-color px-3 py-2">
        <span [class]="item.icon"></span>
        <span class="ml-2">{{ item.label }}</span>
      </a>
      } @else {

      <span class="flex items-center cursor-pointer text-surface-700 dark:text-surface-0 px-4 py-2">
        <span [class]="item.icon"></span>
        <span class="ml-2">{{ item.label }}</span>
        <i *ngIf="item.items" class="pi pi-angle-down text-primary ml-auto"></i>
      </span>

      }
    }
  </ng-template>

however doing that makes it so only the text is clickable to go route.

Also (although this may just be my inexperience), i cant seem to get the borders of the panels to be hidden. I think the best solution is to add the routerLink to the header template if one exists & to not render items with routerLinks on root.

@SippieCup
Copy link

@cetincakiroglu I believe it is from this <a> tag being outside of the container that is checking for itemTemplate.

This causes it to render both the item template, and the additional link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Needs More Information More information about the issue is needed to find a correct solution
Projects
None yet
Development

No branches or pull requests

5 participants