@@ -24,6 +24,16 @@ class Tags extends React.Component {
2424 } ) ;
2525 }
2626
27+ addTag = text => {
28+ this . setState (
29+ {
30+ tags : [ ...this . state . tags , text . trim ( ) ] ,
31+ text : " "
32+ } ,
33+ ( ) => this . props . onChangeTags && this . props . onChangeTags ( this . state . tags )
34+ ) ;
35+ } ;
36+
2737 onChangeText = text => {
2838 if ( text . length === 0 ) {
2939 // `onKeyPress` isn't currently supported on Android; I've placed an extra
@@ -42,19 +52,20 @@ class Tags extends React.Component {
4252 this . props . createTagOnString . includes ( text . slice ( - 1 ) ) &&
4353 ! ( this . state . tags . indexOf ( text . slice ( 0 , - 1 ) . trim ( ) ) > - 1 )
4454 ) {
45- this . setState (
46- {
47- tags : [ ...this . state . tags , text . slice ( 0 , - 1 ) . trim ( ) ] ,
48- text : " "
49- } ,
50- ( ) =>
51- this . props . onChangeTags && this . props . onChangeTags ( this . state . tags )
52- ) ;
55+ this . addTag ( text . slice ( 0 , - 1 ) ) ;
5356 } else {
5457 this . setState ( { text } ) ;
5558 }
5659 } ;
5760
61+ onSubmitEditing = ( ) => {
62+ if ( ! this . props . createTagOnReturn ) {
63+ return ;
64+ }
65+
66+ this . addTag ( this . state . text ) ;
67+ } ;
68+
5869 render ( ) {
5970 const {
6071 containerStyle,
@@ -107,6 +118,7 @@ class Tags extends React.Component {
107118 value = { this . state . text }
108119 style = { [ styles . textInput , inputStyle ] }
109120 onChangeText = { this . onChangeText }
121+ onSubmitEditing = { this . onSubmitEditing }
110122 underlineColorAndroid = "transparent"
111123 />
112124 </ View >
@@ -120,6 +132,7 @@ Tags.defaultProps = {
120132 initialTags : [ ] ,
121133 initialText : " " ,
122134 createTagOnString : [ "," , " " ] ,
135+ createTagOnReturn : false ,
123136 readonly : false ,
124137 deleteOnTagPress : true ,
125138 maxNumberOfTags : Number . POSITIVE_INFINITY
@@ -129,6 +142,7 @@ Tags.propTypes = {
129142 initialText : PropTypes . string ,
130143 initialTags : PropTypes . arrayOf ( PropTypes . string ) ,
131144 createTagOnString : PropTypes . array ,
145+ createTagOnReturn : PropTypes . bool ,
132146 onChangeTags : PropTypes . func ,
133147 readonly : PropTypes . bool ,
134148 maxNumberOfTags : PropTypes . number ,
0 commit comments