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

Component: ContextMenu Items Do Not Re-render When Changed #13474

Closed
bsnuggs1 opened this issue Aug 9, 2023 · 2 comments
Closed

Component: ContextMenu Items Do Not Re-render When Changed #13474

bsnuggs1 opened this issue Aug 9, 2023 · 2 comments

Comments

@bsnuggs1
Copy link

bsnuggs1 commented Aug 9, 2023

Describe the bug

Problem

Our team had upgraded to using v16.1.0 and noticed a bug with the ContextMenu. It seems like if the ContextMenu's model property is updated after initially being set, it will only render the items for the first time and never any subsequent changes (ex. Array initializes with items 1,2,3 and is rendered as a Context Menu with items 1,2,3. If Array has item 2 removed and is set to the Context Menu, Context Menu continues rendering with items 1,2,3, not 1,3)

This seems to be due to the processedItems change in the following lines of code:
https://github.com/primefaces/primeng/blame/1f1cad11a51afa9093e7285455718d81fd674fe1/src/app/components/contextmenu/contextmenu.ts#L499-L504

The conditional prevents the _processedItems property from being updated after it's initially processed by that getter since it's only allowed if the _processedItems is an empty array or undefined, and unfortunately, there are no other places in the logic that modifies the _processedItems besides those highlighted lines from above.

Workaround:

Since _processedItems is not private, if you store the ContextMenu as a property using ViewChild then whatever array that is being updated and supplying the ContextMenu could be designed so you can call ContextMenu._processedItems = [] to clear it so it'll for a re-processing.

Solution:

ContextMenu should update the _processedItems whenever the model property has been updated.

Environment

Provided a stackblitz below, but it seems the template won't work until the following issue is resolved #13024.

Reproducer

https://stackblitz.com/edit/github-anvazm

Angular version

16.1.8

PrimeNG version

16.1.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

v18.15.0

Browser(s)

Chrome

Steps to reproduce the behavior

  1. Right-click the "Right Click Me!" button to get the context menu to appear. Take note of the items.
  2. Close the context menu
  3. Take note of the list of 1, 2, 3
  4. Click on Pop Item
  5. List should now be 1, 2
  6. Repeat step # 1
  7. Items should still be 1, 2, 3 in the context menu, yet the list is 1, 2, despite both deriving from the same list
  8. Close the context menu
  9. Click "Force Context Menu Re-render!"
  10. Repeat step # 1
  11. Items in context menu should now match the list as 1,2

Expected behavior

Expected the contents of the ContextMenu to change when the model property has been provided new or updated lists.

@bsnuggs1 bsnuggs1 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Aug 9, 2023
@oriebalzyuot96
Copy link

@bsnuggs1 look to this bug #13468

@cetincakiroglu
Copy link
Contributor

This issue happens on various menu components, I've opened a generic one and you can track in here #13471

Issue is fixed and the fix will be available with the upcoming release.

Thanks for reporting, closing the issue!

@cetincakiroglu cetincakiroglu removed the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants