Skip to content

Commit

Permalink
feat: add prop dropdownItemStyle (#600)
Browse files Browse the repository at this point in the history
* [Android Dark theme]  Fixed to pass props for Background of popover

* fix(tests): update test configuration and lint fixes
  • Loading branch information
mamtajuddinIncapsulate authored Jul 26, 2024
1 parent 3f4643b commit b5f19ad
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default class RNPickerSelect extends PureComponent {
// Custom Icon
Icon: PropTypes.func,
InputAccessoryView: PropTypes.func,
dropdownItemStyle: PropTypes.shape({}),
};

static defaultProps = {
Expand Down Expand Up @@ -89,6 +90,7 @@ export default class RNPickerSelect extends PureComponent {
Icon: null,
InputAccessoryView: null,
darkTheme: false,
dropdownItemStyle: {},
};

static handlePlaceholder({ placeholder }) {
Expand Down Expand Up @@ -276,10 +278,12 @@ export default class RNPickerSelect extends PureComponent {
renderPickerItems() {
const { items } = this.state;
const defaultItemColor = this.isDarkTheme() ? '#fff' : undefined;
const { dropdownItemStyle } = this.props;

return items.map((item) => {
return (
<Picker.Item
style={dropdownItemStyle}
label={item.label}
value={item.value}
key={item.key || item.label}
Expand Down
24 changes: 24 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,4 +555,28 @@ describe('RNPickerSelect', () => {
});
});
});

it('should apply custom styles to dropdown items', () => {
const customDropdownItemStyle = {
backgroundColor: '#d0d4da',
color: '#000',
};

const wrapper = shallow(
<RNPickerSelect
items={selectItems}
placeholder={placeholder}
onValueChange={noop}
dropdownItemStyle={customDropdownItemStyle}
/>
);

wrapper.find('[testID="ios_touchable_wrapper"]').simulate('press');

const pickerItems = wrapper.find('Picker').find('Picker.Item');

pickerItems.forEach((item) => {
expect(item.props().style).toEqual(customDropdownItemStyle);
});
});
});

0 comments on commit b5f19ad

Please sign in to comment.