Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Repository files navigation

React-Native-Tags

Build Statusnpmnpm version

A React Native component that allows you to input text and formats the text into a tag when a space or comma is entered. Tapping on the tag will remove it.

Demo

Installation

npm install --save react-native-tags
yarn add react-native-tags

Usage

importReactfrom"react";import{TouchableOpacity,Text}from"react-native";importTagsfrom"react-native-tags";constMyTagInput=()=>(<TagsinitialText="monkey"textInputProps={{placeholder: "Any type of animal"}}initialTags={["dog","cat","chicken"]}onChangeTags={tags=>console.log(tags)}onTagPress={(index,tagLabel,event,deleted)=>console.log(index,tagLabel,event,deleted ? "deleted" : "not deleted")}containerStyle={{justifyContent: "center"}}inputStyle={{backgroundColor: "white"}}renderTag={({ tag, index, onPress, deleteTagOnPress, readonly })=>(<TouchableOpacitykey={`${tag}-${index}`}onPress={onPress}><Text>{tag}</Text></TouchableOpacity>)}/>);

Render Props

renderTag

If you would like to add new functionality or modify the way that the tags are rendered then pass in a renderTag prop.

PropNameDescription
tagtext of the tag
indexposition in the array of tags
onPressRemoves the tag if deleteTagsOnPress and readonly is false

Props

PropNameDescriptionDefault
initialTextThe input element's text
textInputPropsforward props to the textInput
initialTags['the', 'initial', 'tags']
createTagOnStringTriggers new tag creation[",", ".", " "]
onChangeTagsFires when tags are added or removed
maxNumberOfTagsThe max number of tags that can be enteredinfinity
onTagPressFires when tags are pressed
readonlyTags cannot be modifiedfalse
deleteTagOnPressRemove the tag when pressedtrue
renderTagManage the rendering of your own Tag

Style modification props

PropNameDescriptionDefault
styleStyle (containerStyle alias)
containerStyleStyle
inputContainerStyleStyle
inputStyleStyle
tagContainerStyleStyle
tagTextStyleStyle

About

Tag input component for React Native

Topics

Resources

Stars

282 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages