From 6c06b1105bc38d1d6f963aeb1db840d9be6b53d5 Mon Sep 17 00:00:00 2001 From: Laura Date: Sun, 13 Sep 2020 22:22:49 -0300 Subject: [PATCH 1/6] Pass onSubmitEditing prop to TextInput on Autocomplete component --- components/Autocomplete/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/Autocomplete/index.js b/components/Autocomplete/index.js index 9cbd740..d2514de 100644 --- a/components/Autocomplete/index.js +++ b/components/Autocomplete/index.js @@ -1,4 +1,3 @@ -import React, {Component, Fragment} from "react"; import {findNodeHandle, ActivityIndicator, TextInput, View} from "react-native"; import {string, bool, number, func} from "prop-types"; import Dropdown from "../Dropdown"; @@ -196,6 +195,7 @@ class Autocomplete extends Component { scrollToInput(findNodeHandle(event.target)); } }} + onSubmitEditing={this.props.onSubmitEditing} /> {loading && ( Date: Fri, 9 Oct 2020 08:47:48 -0300 Subject: [PATCH 2/6] Handle initial value update --- components/Autocomplete/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/components/Autocomplete/index.js b/components/Autocomplete/index.js index d2514de..8895573 100644 --- a/components/Autocomplete/index.js +++ b/components/Autocomplete/index.js @@ -153,6 +153,21 @@ class Autocomplete extends Component { } } + componentDidUpdate(prevProps){ + const shouldUpdateInitialValue = ( + prevProps.initialValue !== this.props.initialValue + && this.state.initialValue !== this.props.initialValue + ); + + if (!shouldUpdateInitialValue){ + return; + } + + this.setState({ + initialValue: this.props.initialValue + }) + } + render() { const {inputValue, items, loading, filteredItems} = this.state; const { From 738acaa4566f7fa2564a78b57347d125986193dd Mon Sep 17 00:00:00 2001 From: Laura Date: Fri, 9 Oct 2020 08:54:59 -0300 Subject: [PATCH 3/6] Add type for onSubmitEditing --- index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 2591e7c..f169b7f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,7 +1,7 @@ // Type definitions for react-native-dropdown-autocomplete 1.0 import * as React from 'react'; -import { ViewStyle, TextStyle, StyleProp, KeyboardTypeOptions } from 'react-native'; +import { ViewStyle, TextStyle, StyleProp, KeyboardTypeOptions, TextInputProps } from 'react-native'; type AutocompleteProps = { autoCorrect?: boolean; @@ -35,7 +35,7 @@ type AutocompleteProps = { pickerStyle?: StyleProp; containerStyle?: StyleProp; scrollStyle?: StyleProp; - + onSubmitEditing?: TextInputProps["onSubmitEditing"]; scrollToInput?: (ev: any) => void; handleSelectItem: (item: any, index: number) => void; onDropdownShow?: () => void; From bdcd2db4a2121d46853a4ddf59de2c6b80a9f643 Mon Sep 17 00:00:00 2001 From: Laura Date: Fri, 9 Oct 2020 08:57:45 -0300 Subject: [PATCH 4/6] Remove unnecessary condition --- components/Autocomplete/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/components/Autocomplete/index.js b/components/Autocomplete/index.js index 8895573..39e098a 100644 --- a/components/Autocomplete/index.js +++ b/components/Autocomplete/index.js @@ -156,7 +156,6 @@ class Autocomplete extends Component { componentDidUpdate(prevProps){ const shouldUpdateInitialValue = ( prevProps.initialValue !== this.props.initialValue - && this.state.initialValue !== this.props.initialValue ); if (!shouldUpdateInitialValue){ From b3865a2dfe4144a4393e5a5b4ff2abf29cf4ef50 Mon Sep 17 00:00:00 2001 From: Laura Date: Fri, 9 Oct 2020 08:58:31 -0300 Subject: [PATCH 5/6] Set inputValue state with initialValue on update --- components/Autocomplete/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/Autocomplete/index.js b/components/Autocomplete/index.js index 39e098a..1044352 100644 --- a/components/Autocomplete/index.js +++ b/components/Autocomplete/index.js @@ -163,7 +163,7 @@ class Autocomplete extends Component { } this.setState({ - initialValue: this.props.initialValue + inputValue: this.props.initialValue }) } From c0635d44fb6a9f1ad7ecd7af7c39c35736e36f8d Mon Sep 17 00:00:00 2001 From: Laura Date: Fri, 9 Oct 2020 09:32:07 -0300 Subject: [PATCH 6/6] Set initial value on mount --- components/Autocomplete/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/Autocomplete/index.js b/components/Autocomplete/index.js index 1044352..9b9f4fa 100644 --- a/components/Autocomplete/index.js +++ b/components/Autocomplete/index.js @@ -133,11 +133,16 @@ class Autocomplete extends Component { } componentDidMount() { - const {data} = this.props; + const {data, initialValue} = this.props; this.mounted = true; + if (data) { this.setState({items: data}); } + + if (initialValue){ + this.setState({ initialValue }) + } } componentWillUnmount() {