5.4.0 • Published 7 months ago

react-native-autocomplete-input v5.4.0

Weekly downloads
14,920
License
MIT
Repository
github
Last release
7 months ago

react-native-autocomplete-input

npm version Test

A pure JS autocomplete component for React Native. Use this component in your own projects or use it as inspiration to build your own autocomplete.

Autocomplete Example

Play around with the Example Snack

How to use react-native-autocomplete-input

Tested with RN >= 0.26.2. If you want to use RN < 0.26 try to install react-native-autocomplete-input <= 0.0.5.

Installation

# Install with npm
$ npm install --save react-native-autocomplete-input

# Install with yarn
$ yarn add react-native-autocomplete-input

Example

// ...

render() {
  const { query } = this.state;
  const data = filterData(query);
  return (
    <Autocomplete
      data={data}
      value={query}
      onChangeText={(text) => this.setState({ query: text })}
      flatListProps={{
        keyExtractor: (_, idx) => idx,
        renderItem: ({ item }) => <Text>{item}</Text>,
      }}
    />
  );
}

// ...

Android

Android does not support overflows (#20), for that reason it is necessary to wrap the autocomplete into a absolute positioned view on Android. This will allow the suggestion list to overlap other views inside your component.

//...

render() {
  return(
    <View>
      <View style={styles.autocompleteContainer}>
        <Autocomplete {/* your props */} />
      </View>
      <View>
        <Text>Some content</Text>
      </View>
    </View>
  );
}

//...

const styles = StyleSheet.create({
  autocompleteContainer: {
    flex: 1,
    left: 0,
    position: 'absolute',
    right: 0,
    top: 0,
    zIndex: 1
  }
});

Props

PropTypeDescription
containerStylestyleThese styles will be applied to the container which surrounds the autocomplete component.
hideResultsboolSet to true to hide the suggestion list.
dataarrayAn array with suggestion items to be rendered in renderItem({ item, i }). Any array with length > 0 will open the suggestion list and any array with length < 1 will hide the list.
inputContainerStylestyleThese styles will be applied to the container which surrounds the textInput component.
listContainerStylestyleThese styles will be applied to the container which surrounds the result list.
listStylestyleThese style will be applied to the result list.
onShowResultsfunctiononShowResults will be called when the autocomplete suggestions appear or disappear.
onStartShouldSetResponderCapturefunctiononStartShouldSetResponderCapture will be passed to the result list view container (onStartShouldSetResponderCapture).
renderTextInputfunctionrender custom TextInput. All props passed to this function.
flatListPropsobjectcustom props to FlatList.
renderResultListfunctionrender custom result list. Can be used to replace FlatList. All props passed to this function.

Known issues

  • By default the autocomplete will not behave as expected inside a <ScrollView />. Set the scroll view's prop to fix this: keyboardShouldPersistTaps={true} for RN <= 0.39, or keyboardShouldPersistTaps='always' for RN >= 0.40. (#5). Alternatively, you can use renderResultList to render a custom result list that does not use FlatList. See the tests for an example.
  • If you want to test with Jest add jest.mock('react-native-autocomplete-input', () => 'Autocomplete'); to your test.

Contribute

Feel free to open issues or do a PR!

5.4.0

7 months ago

5.3.2

1 year ago

5.3.1

1 year ago

5.3.0

1 year ago

5.2.1

1 year ago

5.2.0-alpha.0

1 year ago

5.1.1-alpha.0

1 year ago

5.1.1-alpha.1

1 year ago

5.2.0

2 years ago

5.1.1

2 years ago

5.1.0

2 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

5.0.0-beta.0

3 years ago

4.2.0

4 years ago

4.2.0-rc.2

4 years ago

4.2.0-rc.1

5 years ago

4.2.0-rc.0

5 years ago

4.1.0

5 years ago

4.0.0

5 years ago

3.6.0

6 years ago

3.6.0-rc

6 years ago

3.5.0

6 years ago

3.4.0

7 years ago

3.3.1

7 years ago

3.3.0

7 years ago

3.2.1

7 years ago

3.2.0

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

3.0.0-rc.1

7 years ago

3.0.0-rc.0

7 years ago

2.1.0

7 years ago

2.0.0

8 years ago

2.0.0-rc.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago