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: onChange listener is not consistent in the event.value which is getting returned #7064

Closed
Anandhex opened this issue Aug 20, 2024 · 2 comments · Fixed by #7083
Closed
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@Anandhex
Copy link

Describe the bug

event.value is not consistent when there is empty value selected with the dropdown.
The value getting returned is an object instead of a string

Reproducer

https://stackblitz.com/edit/vitejs-vite-jemedx?file=src%2FApp.tsx

System Information

System:
OS: Linux 5.0 undefined
CPU: (6) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 18.20.3 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
primereact: 10.8.2 => 10.8.1
react: ^18.2.0 => 18.2.0

Steps to reproduce the behavior

  1. Click on the dropdown item "All".
  2. Observe the e.value returns as {name:"All",value:""}
  3. Click on the dropdown item "Active".
  4. Observe the e.value returns as "active".

Expected behavior

The e.value when the value is empty should return empty value (i.e, "" )

@Anandhex Anandhex 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 20, 2024
@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 Aug 20, 2024
@melloware
Copy link
Member

Bug is right here:

const getOptionValue = (option) => {
const optionValue = props.optionValue ? ObjectUtils.resolveFieldData(option, props.optionValue) : option ? option['value'] : ObjectUtils.resolveFieldData(option, 'value');
return ObjectUtils.isNotEmpty(optionValue) ? optionValue : option;
};

@mtsh1000
Copy link

I think line 830 should be changed to:

return props.optionValue ? optionValue : option;

and that would fix bugs with empty string and null dropdown values

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

Successfully merging a pull request may close this issue.

3 participants