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: Dropdown #14367

Closed
Draganlazarev90 opened this issue Dec 14, 2023 · 6 comments · Fixed by #14643
Closed

Component: Dropdown #14367

Draganlazarev90 opened this issue Dec 14, 2023 · 6 comments · Fixed by #14643
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@Draganlazarev90
Copy link

Draganlazarev90 commented Dec 14, 2023

Describe the bug

Having <ng-template let-item pTemplate="selectedItem">{{ item.label }}</ng-template>
throws Cannot read properties of undefined (reading 'label') error if no item is selected initially, while if you have [filter]="true" and you have a selected an item, then start typing in the filter input the selected item is not displayed

Environment

https://stackblitz.com/edit/stackblitz-starters-5fabhi

Reproducer

No response

Angular version

17.0.5

PrimeNG version

17.1

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

  1. Open the dropdown and select an item while filtering is enabled
  2. Open the dropdown and start typing something different than the selected value
  3. The selectedItem value disappears

Expected behavior

No response

@Draganlazarev90 Draganlazarev90 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 14, 2023
@rburgst
Copy link

rburgst commented Dec 14, 2023

after #14241, this is the 2nd major issue for the dropdown component. I would warn anyone from upgrading to 17, IMHO it didnt have enough time to bake.

@Draganlazarev90 note that your stackblitz is still on angular 16 and primeng 16.9.1

        "primeng": "16.9.1",

@jpgoelz
Copy link

jpgoelz commented Dec 18, 2023

Since 16.6.0 PrimeNG has constantly broken our builds, and we are now reluctant to even update anything.

I would advise implementing more tests for the components so they do not break on every other pull request.

@jpgoelz
Copy link

jpgoelz commented Dec 18, 2023

@Draganlazarev90, try surrounding the content of the template with an <ng-containger *ngIf="item"></ng-container> like this:

<ng-template let-item pTemplate="selectedItem">
  <ng-containger *ngIf="item"> {{ item.label }} </ng-container>
</ng-template>

The actual bug is that the template is used even if there is no element selected.

@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 Jan 5, 2024
@KeithGillette
Copy link
Contributor

KeithGillette commented Jan 6, 2024

I've seen multiple bugfixes for p-dropdown in recent releases but apparently none for this issue, which we are also experiencing in an Angular 17.0.8 project in attempting to update to any version of PrimeNG 17, including 17.3.1.

Adding an optional chaining operator prevents the error, but this was not required before.

<ng-template let-item pTemplate="selectedItem">{{ item?.label }}</ng-template>

@lawcha
Copy link

lawcha commented Jan 22, 2024

In my case, until version 15.4.1, when I pass the items to the p-dropdown, the first item is selected by default, which is not the case since v16. Having that error is just a side-effect of not having a default value in my opinion. Does someone knows something about that missing default value ?

@rosenthalj
Copy link
Contributor

This issue is really two bugs :

  1. Having {{ item.label }}
    throws Cannot read properties of undefined (reading 'label') error if no item is selected initially
  2. if you have [filter]="true" and you have a selected an item, then start typing in the filter input the selected item is not displayed
    (Note: these descriptions were taken directly from this "Describe the bug" section at the top of this issue)

After examining the changes in pull request #14643, it appears that only the first bug of this issue is fixed by pull request #14643. The "very simple demo" reproducer provided in the pull request only addresses the first part of this issue

The second bug of this issue is related to issue #14596. The pull request #14665 fixes issue #14596 and also fixes the second bug of this issue.

The first video listed below is running this issues original reproducer(https://stackblitz.com/edit/stackblitz-starters-5fabhi) and "only" demonstrates the second bug of the issues.

DropdownFilterWithTemplateBug.mov

The second video listed below is with the changes from pull request #14665 and shows bug 2 of this issue has been fixed

DropdownFilterWithTemplateFix.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants