diff --git a/components/Autocomplete/index.js b/components/Autocomplete/index.js index 9cbd740..9b9f4fa 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"; @@ -134,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() { @@ -154,6 +158,20 @@ class Autocomplete extends Component { } } + componentDidUpdate(prevProps){ + const shouldUpdateInitialValue = ( + prevProps.initialValue !== this.props.initialValue + ); + + if (!shouldUpdateInitialValue){ + return; + } + + this.setState({ + inputValue: this.props.initialValue + }) + } + render() { const {inputValue, items, loading, filteredItems} = this.state; const { @@ -196,6 +214,7 @@ class Autocomplete extends Component { scrollToInput(findNodeHandle(event.target)); } }} + onSubmitEditing={this.props.onSubmitEditing} /> {loading && ( ; containerStyle?: StyleProp; scrollStyle?: StyleProp; - + onSubmitEditing?: TextInputProps["onSubmitEditing"]; scrollToInput?: (ev: any) => void; handleSelectItem: (item: any, index: number) => void; onDropdownShow?: () => void;