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

Dropdown: when using selectedItem template if the selected option is 0 then no template is rendered #15366

Closed
frabonomi opened this issue Apr 25, 2024 · 2 comments · Fixed by #15806
Assignees
Labels
LTS-16-PORTABLE LTS-FIXED-16.9.11 Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@frabonomi
Copy link

frabonomi commented Apr 25, 2024

Describe the bug

When using the p-dropdown component with a custom selectedItem template to customize the selected label display as per documentation, the template isn't rendered if the selected option equals to 0.

PrimeNG Dropdown issue when the selected option is 0

From a quick look at the code it seems that this is happening because of the condition selectedItemTemplate && selectedOption. In my case the selectedOption is 0 and is therefore considered falsy, but it should be a treated as a possible valid value.

In a way it seems to be related to issue #14954

Environment

MacOS 14.2.1

Reproducer

https://stackblitz.com/edit/github-41pgth?file=src%2Fapp%2Fapp.component.html

Angular version

17.3.5

PrimeNG version

17.14.1

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

LTS

Browser(s)

No response

Steps to reproduce the behavior

  1. Add a p-dropdown component
  2. Set its options to an array containing a value that is 0
  3. Define a custom selectedItem template
  4. Select the option with the value 0

Expected behavior

The custom template should be rendered even if the selected option is 0.

@frabonomi frabonomi added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Apr 25, 2024
@frabonomi frabonomi changed the title Dropdown: when using selectedItem template if the selected option is 0 then no template is shown Dropdown: when using selectedItem template if the selected option is 0 then no template is rendered Apr 25, 2024
@frabonomi
Copy link
Author

Happy to open a PR for this, if needed ☝️

@frabonomi
Copy link
Author

I think the main use case for this is when the options values are coming from an enum (without an initializer):

enum Direction {
  Up, // === 0
  Down,
  Left,
  Right,
}

@mehmetcetin01140 mehmetcetin01140 removed the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jun 6, 2024
@mehmetcetin01140 mehmetcetin01140 added this to the 17.18.1 milestone Jun 6, 2024
@mehmetcetin01140 mehmetcetin01140 added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Jun 6, 2024
@mehmetcetin01140 mehmetcetin01140 self-assigned this Jun 7, 2024
mehmetcetin01140 added a commit that referenced this issue Jun 7, 2024
…cted option is 0 then no template is rendered
cetincakiroglu added a commit that referenced this issue Jun 13, 2024
Fixed #15366 - Dropdown: when using selectedItem template if the sele…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTS-16-PORTABLE LTS-FIXED-16.9.11 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.

2 participants