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

Form.Select not displaying two distinct text fields if their value fields are identical. #4420

Open
DamianCaine opened this issue Mar 3, 2023 · 2 comments

Comments

@DamianCaine
Copy link

If two or more options in the options prop have the same value in their respective value fields, the Select component only highlights one option for all such cases. For example,
const options = [{key:1, text: "opt", value: "opt546"}, {key:2, text: "newOpt", value: "opt546"}, {key:3, text: "diffOpt", value: "opt54"}];
In here, whether we choose "opt" or "newOpt", the Select component only displays "opt" in the input box. Only if the value fields are unique, is it considering the text fields separately.

@welcome
Copy link

welcome bot commented Mar 3, 2023

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

@naman1608
Copy link
Contributor

naman1608 commented Sep 5, 2023

@layershifter in the dropdown handleClick function, it is comparing the current value and the new value, instead shouldn't it be comparing they keys instead as the keys will always be unique? this may solve the issue. could you guide please

`
const newValue = multiple ? .union(this.state.value, [value]) : value
const valueHasChanged = multiple
? !!
.difference(newValue, currentValue).length
: newValue !== currentValue

// notify the onChange prop that the user is trying to change value
if (valueHasChanged) {
  this.setState({ value: newValue })
  this.handleChange(e, newValue)
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants