react-component / react-component/select
Value property must be unique / incorrect option passed to onSelect
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 938
- Forks
- 482
- Avg merge
- 15h 8m
- Merged PRs (30d)
- 2
Description
Demo:
https://codesandbox.io/s/exciting-bird-x7m1kf?file=/src/App.js
Steps to reproduce:
- Click to input, dropdown opens;
- Click on first option;
- Click to input again;
- Click on second option;
- Observe console output
Expected behavior:
After first click, option with 'key: "id1"' should be passed to onSelect. After second click, option with 'key: "id2"' should be passed to onSelect
Actual behavior:
Same option is passed to onSelect (id3) regardless which option I select.
Comment:
It's not stated anywhere that value prop must be unique, which in many cases is not satisfying - movies, companies, books etc. can have same name but unique ID. In my case, same values might have highlighted different parts of string - I can not use options prop. I also can not pass id to value, since I need backfill.
One possible solution would be to keep uniqueness only to keys. Other (which will solve only my case) to do backfill with different prop - title, label or something else and fill it with value as a backup.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodeSandbox at src/App.js and reproduce the selection sequence, then trace how value and key are used before onSelect receives an option. Done means selecting entries with duplicate values passes the corresponding keyed options, including the reported id1, id2, and id3 case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100