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

Option with value 0 has different behavior than any other number in dropdown #6617

Open
espentveit opened this issue May 13, 2024 · 6 comments
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@espentveit
Copy link

espentveit commented May 13, 2024

Describe the bug

Hi,

Seems like the behavior has been changed by commit 7312fe4.

return props.optionValue ? ObjectUtils.resolveFieldData(option, props.optionValue) : ObjectUtils.resolveFieldData(option, 'value') || option;

The || here passes option through if the value is 0.

0 || "Test" == "Test"
true

Reproducer

No response

PrimeReact version

10.6.5

React version

18.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

@espentveit espentveit added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label May 13, 2024
@melloware
Copy link
Member

cc @Rekl0w

@melloware
Copy link
Member

it probably needs to be ObjectUtils.isNotEmpty(props.optionValue)

@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels May 13, 2024
@Rekl0w
Copy link
Contributor

Rekl0w commented May 13, 2024

No, it is weird that i tried almost everything but not works for this. I also tried to use old version of this function but still the same behavior. I guess this is another bug. @melloware

@espentveit
Copy link
Author

espentveit commented May 13, 2024

The case where I tested was for the one with the 'value' key set. Maybe the isNotEmpty should check the output of resolveFieldData?

const getOptionValue = (option) => {
  if (props.optionValue) {
    return ObjectUtils.resolveFieldData(option, props.optionValue);
  } else {
    const optionValue = ObjectUtils.resolveFieldData(option, "value");
    return ObjectUtils.isNotEmpty(optionValue) ? optionValue : option;
  }
};

Edit:
Or maybe use

const getOptionValue = (option) => {
  if (props.optionValue) {
    return ObjectUtils.resolveFieldData(option, props.optionValue);
  } else {
    return option.hasOwnProperty("value") ? ObjectUtils.resolveFieldData(option, "value") : option;
  }
};

@melloware melloware added this to the 10.7.0 milestone May 13, 2024
@Rekl0w
Copy link
Contributor

Rekl0w commented May 13, 2024

Both codes causes the blank dropdown options.

image

If you try the old codes before i've changed, it behaves the same. Like i said i don't think that code causes this bug.

@espentveit
Copy link
Author

Ok. I'll test some more tomorrow

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

No branches or pull requests

4 participants