react-native-picker-select
react-native-picker-select copied to clipboard
Added support for itemKey property in RNPickerSelect component
Description
This PR enhances the RNPickerSelect
component by adding support for the itemKey
property. This allows for better handling of items with identical values but unique keys, providing a more robust selection mechanism. The changes include updates to the prop types, the constructor, and the getSelectedItem
and componentDidUpdate
methods to utilize itemKey
correctly.
Changes Made
- Added
itemKey
prop toRNPickerSelect
PropTypes. - Updated the
constructor
to handleitemKey
. - Modified
getSelectedItem
method to useitemKey
for item selection. - Updated
componentDidUpdate
to check for changes initemKey
andvalue
.
Related Issue
- This PR addresses issue #580 (Replace with actual issue number if applicable).
Motivation and Context
The itemKey
property ensures that items with identical values can be uniquely identified and selected. This is particularly useful in scenarios where the same value might be associated with different keys, improving the flexibility and reliability of the component.
How Has This Been Tested?
- Manually tested on both iOS and Android platforms.
- Verified that the correct item is selected when using
itemKey
. - Ensured backward compatibility with existing usage of the component without
itemKey
.
Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)
- [x] Documentation update
Checklist
- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
- [x] I have read the CONTRIBUTING document.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
Additional Notes
Please review the changes and let me know if there are any adjustments needed. Thank you!