Skip to content

Commit

Permalink
feat(placeholder-support): added placeholder for pickers
Browse files Browse the repository at this point in the history
 - in IOS it works perfect, as we implement picker in custom-keyboard component.
 - for android, we need to add an extra item in the `Picker.item` list as placeholder value.
There is drawback of this approach in android that, the placeholder will appear as first value in drop-down list of picker
  • Loading branch information
princeTPG committed Jul 19, 2021
1 parent 28776c3 commit 29643bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/components/AbstractSelectInput/AbstractSelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ class AbstractSelectInput extends Component {
}

getValueLabel = () => {
const { options, value } = this.props
const { options, value, placeholder } = this.props
const valueOptions = options || [{ value: '', label: '' }]

if (!value && placeholder) return placeholder

return (
valueOptions.map(function(option) {
if (option.value === value) {
Expand Down
11 changes: 10 additions & 1 deletion src/components/SelectInput.android/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class SelectInput extends AbstractSelectInput {
options,
style,
backgroundColor,
dropdownIconColor
dropdownIconColor,
placeholder
} = this.props
const { selectedValue } = this.state

Expand All @@ -31,6 +32,14 @@ class SelectInput extends AbstractSelectInput {
selectedValue={selectedValue}
mode={mode}
>
{!!placeholder && (
<Picker.Item
key={placeholder}
value=""
label={placeholder}
enabled={false}
/>
)}
{options.map(option => (
<Picker.Item
key={option.value}
Expand Down

0 comments on commit 29643bc

Please sign in to comment.