peterp / react-native-tags

Tag input component for React Native
MIT License
288 stars 75 forks source link

initial text for each tags #68

Open hakimscode opened 3 years ago

hakimscode commented 3 years ago

Hello @peterp ,

I was wondering if there is feature for initial text for each tags. Because, in props initialText just affect on the first tag. So it would be nice if the initial text also implement on every tags.

For example I want user to automatically input tags with the first character is '#'.

I try to modified your library, just basically add a new props initialEachText and put it on

showLastTag = () => {
    this.setState(state =>
      ({
        tags: state.tags.slice(0, -1),
        text: state.tags.slice(-1)[0] || this.state.initialEachText
      }),
      () =>
        this.props.onChangeTags && this.props.onChangeTags(this.state.tags)
    );
  };

  addTag = text => {
    this.setState(state =>
      ({
        tags: [...state.tags, text.trim()],
        text: this.state.initialEachText
      }),
      () => this.props.onChangeTags && this.props.onChangeTags(this.state.tags)
    );
  };

Just changed the " " (space) to initialEachText that can be modified.

And I just set the props initialText={'#'} and initialEachText={'#'}.

This would be great if you considering to add this feature. Thank you 🤝