@@ -39,7 +39,7 @@ class Tags extends React.Component {
3939 ) ;
4040 } else if (
4141 text . length > 1 &&
42- ( text . slice ( - 1 ) === " " || text . slice ( - 1 ) === "," )
42+ ( text . slice ( - 1 ) === " " || text . slice ( - 1 ) === "," ) && ! ( this . state . tags . indexOf ( text . slice ( 0 , - 1 ) . trim ( ) ) > - 1 )
4343 ) {
4444 this . setState (
4545 {
@@ -54,6 +54,22 @@ class Tags extends React.Component {
5454 }
5555 } ;
5656
57+
58+ /**
59+ * void arraySplice(tag)
60+ * uses the array.filter() method provided in Javascript to remove the specific tag from the list.
61+ *
62+ * @param {string } tag
63+ */
64+ arraySplice ( tag ) {
65+ if ( this . props . deleteOnPress == true ) {
66+ this . setState ( {
67+ tags : this . state . tags . filter ( e => e !== tag )
68+ } ) ;
69+ }
70+ }
71+
72+
5773 render ( ) {
5874 return (
5975 < View
@@ -63,13 +79,17 @@ class Tags extends React.Component {
6379 < Tag
6480 key = { i }
6581 label = { tag }
66- onPress = { e => this . props . onTagPress ( i , tag , e ) }
82+ onPress = { e => {
83+ this . arraySplice ( tag )
84+ this . props . onTagPress ( i , tag , e )
85+ } }
6786 readonly = { this . props . readonly }
6887 tagContainerStyle = { this . props . tagContainerStyle }
6988 tagTextStyle = { this . props . tagTextStyle }
7089 />
7190 ) ) }
72- { ! this . props . readonly && (
91+
92+ { ! this . props . readonly && ( this . props . maxNumberOfTags > this . state . tags . length ) && (
7393 < View style = { [ styles . textInputContainer ] } >
7494 < TextInput
7595 value = { this . state . text }
@@ -94,13 +114,14 @@ Tags.propTypes = {
94114 initialText : PropTypes . string ,
95115 initialTags : PropTypes . arrayOf ( PropTypes . string ) ,
96116 onChangeTags : PropTypes . func ,
97- onTagPress : PropTypes . func ,
98117 containerStyle : PropTypes . object ,
99118 style : PropTypes . object ,
100119 inputStyle : PropTypes . object ,
101120 tagContainerStyle : PropTypes . object ,
102121 tagTextStyle : PropTypes . object ,
103- readonly : PropTypes . bool
122+ readonly : PropTypes . bool ,
123+ maxNumberOfTags : PropTypes . number ,
124+ deleteOnPress : PropTypes . bool
104125} ;
105126
106127export { Tag } ;
0 commit comments