Search code examples
angularprimeng

Add Dropdown Option on Opening a Grouped Dropdown


When the user opens the dropdown list, I want to add an dropdown item.

This is no problem in an ungrouped dropdown, but when I set [group]="true" this does not seem to work any longer...

I reproduced the issue in a minimal stackblitz here.


Solution

  • There is indeed an apparent issue with the p-dropdown not updating the options when the group option is set to true. A workaround for the situation is adding the following snippet after the unshift happens in the addoption.directive.ts:

          // Reassigning options to satisfty p-dropdown not updating the list when the group option is true
          const options = this.dropdown.options;
          this.dropdown.options = [];
          this.dropdown.options = options;
    

    I suggest you contact PrimeNG and find out why this happens and if it is known/ purposeful behavior.

    I hope my answer helped you. Wishing you a wonderful day!