Giter Club home page Giter Club logo

react-native-tag-autocomplete's Introduction

react-native-tag-autocomplete

Tag autocomplete component for contacts, groups, etc.

Example

Up and Running

$ npm install --save react-native-tag-autocomplete

Example

//...
import AutoTags from 'react-native-tag-autocomplete';
// ...
state = {
    suggestions : [ {name:'Mickey Mouse'}, ],
    tagsSelected : []
}

handleDelete = index => {
   let tagsSelected = this.state.tagsSelected;
   tagsSelected.splice(index, 1);
   this.setState({ tagsSelected });
}

handleAddition = suggestion => {
   this.setState({ tagsSelected: this.state.tagsSelected.concat([suggestion]) });
}

render() {
  return (
      <AutoTags
            suggestions={this.state.suggestions}
            tagsSelected={this.state.tagsSelected}
            handleAddition={this.handleAddition}
            handleDelete={this.handleDelete}
            placeholder="Add a contact.." />
    );
}
// ...

Props

Prop Type Required Description
suggestions array yes Array of suggestion objects. They must have a 'name' prop if not overriding filter && renderTags
tagsSelected array yes List of tags that have already been selected
handleAddition function yes Handler for when suggestion is selected (normally just push to tagsSelected)
handleDelete function yes Handler called with index when tag is clicked
placeholder string no Input placeholder
renderTags function no Override the render tags and it's styles
renderSuggestion function no Override the suggestions dropdown items
filterData function no Override the search function, allows you to filter by props other than name
onCustomTagCreated function no Function called with user input when user presses enter
createTagOnSpace boolean no calls onCustomTagCreated when user presses space
tagStyles object no Override the default tag styling
tagsOrientedBelow boolean no Move tags below the input instead of above (default).

Android

This repository wraps react-native-autocomplete-input, so their limitations will also apply here.

As such:

"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}>
        <AutoTags {/* 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
  }
});

Pull Requests

I'm a dummy, so any PR's are wholly appreciated <3.

react-native-tag-autocomplete's People

Contributors

alexrbrown avatar dependabot[bot] avatar joeroddy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-native-tag-autocomplete's Issues

Not working on IOS

React-native-tag-autocomplete is not working on IOS and perfectly working on Android. Please provide me a fix. Thanks in advance

entered text is not on the suggestions

How do we make the same effect (circled) if the text entered is not in one of the suggestions array? In this case, 'tambayan' is not in the list. Thank you.

image

How to add scrollbar in suggestion list

My suggestion list is too long to view on a page hence, it is hidden when page ends and i can not see all the suggestions, s how can i add a scroll bar in suggestions list so that user can scroll down the list and no record gets lost.

image

Why cursor moves to next line?

Can we have cursor next to the tag we just created/selected?
Can we use back/clear press to remove tags?

I am trying to enact what Gmail app does (the To parameter of Gmail app)

Getting module error

Hi, Just installed and when I imported it in the app, I am getting this error:

image
Did everything presented in the error but no luck, any suggestions?

Style List and Add new

Hi thanks for the work on this been helpful. couple of questions:

  1. is there any plans to enable ability to style the dropdown list of suggested selection
  2. limit inputs to 1

Thanks again.

Virtualize key error

I'm having this warning VirtualizedList: missing keys for items, make sure to specify a key or id property on each item or provide a custom keyExtractor. how to solve this one?

Android: tag input row float on top of other elements

To make the autocomplete working in Android, I added a wrapper with the style below:

  autocompleteContainer: {
    flex: 1,
    left: 0,
    position: 'absolute',
    right: 0,
    top: 100,  //<<==make tag input below 2 input elements
    zIndex: 1
  },

Here top is increased to 100 to give space for other 2 input elements. Here is the render code:

import {Textarea, Item, Icon, Input, Text,  Header, Container, Content, Form } from 'native-base';

 return (
           
    <Container style={styles.container}>
        
            <Header>
                //header
            </Header>
            
            <Content style={styles.contentContainer}
                showsHorizontalScrollIndicator={false}
                showsVerticalScrollIndicator={false}
                >
                    <Form>
                        <Input onChangeText={nameChange} placeholder={'Name'} />  //<<==input Name
                        <Textarea padder rowSpan={2} bordered placeholder="Spec" onChangeText={despChange} />  //<<==input desp
                        
                        <View style={styles.autocompleteContainer}>  //<<==View wrapper
                        <AutoTags  //<<==here is tag input
                            style={styles.tags}
                            keyExtractor={(item, index) => item + index}
                            suggestions={tagSelection}
                            tagsSelected={tagSelected}
                            handleAddition={addTag}
                            handleDelete={deleteTag}
                            placeholder="Tag.." />
                        </View>
                    </Form>
        ...
   )

Here is how the screen look like:

Capture

Now the tag input field is on top of rest of the view and overlap. how to make the tag input align with other elements?

The autocomplete input have a display issue on Ipad

I used react-native-tag-autocomplete in my app. Everything is OK on Android and Iphone, but when I run app on Ipad, it has a problem in display in the picture I attached.
I set marginLeft is 20, but at first, the input text display in the center of the screen. When I select an item on suggestions, it displays on the left with margin left is 20.
Please help me. Thanks so much.
auto_error

How to limit the number of text input boxes.

Thanks for the great package, do you have a way to limit the number of text input boxes? I want a user to only be able to select one tag. (once 1 tag has been selected no further text input boxes should be displayed).

Incompatible with react-native-autocomplete-input 5.x

After having upgraded all my dependencies, including this library and its dependency react-native-autocomplete-input, I'm facing the following error :

Error: Objects are not valid as a React child (found: object with keys {id, first_name, last_name, locale, code, trigram, _model, name}). If you meant to render a collection of children, use an array instead.

This is due to the fact that since version 5.x of react-native-autocomplete-input, the renderItem has been moved within the flatListProps like so :

diff --git a/node_modules/react-native-tag-autocomplete/index.js b/node_modules/react-native-tag-autocomplete/index.js
index 291f3e0..95b8aab 100644
--- a/node_modules/react-native-tag-autocomplete/index.js
+++ b/node_modules/react-native-tag-autocomplete/index.js
@@ -122,15 +122,17 @@ export default class AutoTags extends Component {
           onSubmitEditing={this.onSubmitEditing}
           multiline={true}
           autoFocus={this.props.autoFocus === false ? false : true}
-          renderItem={({ item, i }) => (
-            <TouchableOpacity onPress={e => this.addTag(item)}>
-              {this.props.renderSuggestion ? (
-                this.props.renderSuggestion(item)
-              ) : (
-                <Text>{item.name}</Text>
-              )}
-            </TouchableOpacity>
-          )}
+          flatListProps={{
+            renderItem: ({ item, i }) => (
+              <TouchableOpacity onPress={e => this.addTag(item)}>
+                {this.props.renderSuggestion ? (
+                  this.props.renderSuggestion(item)
+                ) : (
+                  <Text>{item.name}</Text>
+                )}
+              </TouchableOpacity>
+            )
+          }}
           inputContainerStyle={
             this.props.inputContainerStyle || styles.inputContainerStyle
           }

With this update, this library is compatible with react-native-autocomplete-input 5.x.

Either this lib should stick to the react-native-autocomplete-input 4.2.x version or be patched with the above.

Custom dropdown list template

Hi, thank you for the great work,
I'm looking for a way to implement this library but with a custom template for the dropdown list, example: displaying an icon flag on the right side
is there a way we can add our own template?

thank you so much.

Enter Press does not create the tag .

While Creating a tag by pressing the Enter Key does not work for me. Anyhow it recognizes the Space Key and works properly.
<AutoTags
suggestions={this.state.items}
tagsSelected={this.state.selectedItems}
handleAddition={this.handleAddition}
handleDelete={this.handleDelete}
onCustomTagCreated={(value) => this.handleInput(value)}
createTagOnSpace={true}
placeholder="Choose Cliks to share" />

handleDelete = index => {
let tagsSelected = this.state.selectedItems;
tagsSelected.splice(index, 1);
this.setState({ selectedItems: tagsSelected });
}

handleAddition = suggestion => {
    this.setState({ selectedItems: this.state.selectedItems.concat([suggestion]) });
}

handleInput = (value) => {
    this.setState({ selectedItems: this.state.selectedItems.concat([{ "name": value }]) });
}

I Have tested the code on Both Mobile and Web platforms. but :(

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.