diff --git a/src/withPickerValues/PickerModal.js b/src/withPickerValues/PickerModal.js index 86d3824..f174c1f 100644 --- a/src/withPickerValues/PickerModal.js +++ b/src/withPickerValues/PickerModal.js @@ -18,11 +18,15 @@ class PickerModal extends PureComponent { onValueChange = (value: any) => { if (this.props.onChangeText) this.props.onChangeText(value); + if (this.props.onSubmitEditing) this.props.onSubmitEditing(); + if (this.pickerModal) this.pickerModal.close(); }; renderPicker = () => { - const { values, placeholder, value } = this.props; - if (values && Platform.OS === 'ios') { + const { placeholder, value } = this.props; + if (!this.props.values || !this.props.values.length) return null; + const values = [...this.props.values]; + if (Platform.OS === 'ios') { values.unshift({ value: '', label: placeholder }); } const picker = ( @@ -40,7 +44,16 @@ class PickerModal extends PureComponent { {picker} ) : ( - + {picker} ); diff --git a/src/withPickerValues/withPickerValues.js b/src/withPickerValues/withPickerValues.js index 9922420..bdb80a4 100644 --- a/src/withPickerValues/withPickerValues.js +++ b/src/withPickerValues/withPickerValues.js @@ -3,13 +3,22 @@ import React from 'react'; import PickerModal from './PickerModal'; -const withPickerModal = Component => props => { - const selectedItem = props.values.find(item => item.value === props.value); - return ( - - - - ); +const withPickerModal = Component => { + class WithPickerModal extends React.Component<$FlowFixMeProps, $FlowFixMeState> { + render() { + const selectedItem = + this.props.values && this.props.values.length > 0 + ? this.props.values.find(item => item && item.value === this.props.value) + : undefined; + return ( + + + + ); + } + } + + return WithPickerModal; }; export default withPickerModal;