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

Commit

Permalink
Allow tag creation trigger to be custom.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterp committed Sep 16, 2018
1 parent 71c0c85 commit 62606f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,19 @@ const UselessComponent = () => (

## Props

| PropName | Description | Default |
| ------------------- | ------------------------------------------ | -------- |
| initialText | The input element's text | |
| initialTags | ['the', 'initial', 'tags'] | |
| onChangeTags | Fires when tags are added or removed | |
| maxNumberOfTags | The max number of tags that can be entered | infinity |
| onTagPress | Fires when tags are pressed | |
| readonly | Tags cannot be modified | false |
| deleteTagOnPress | Remove the tag when pressed | true |
| containerStyle | Style | |
| style | Style (`containerStyle` alias) | |
| inputContainerStyle | Style | |
| inputStyle | Style | |
| tagContainerStyle | Style | |
| tagTextStyle | Style | |
| PropName | Description | Default |
| ------------------- | ------------------------------------------ | --------------- |
| initialText | The input element's text | |
| initialTags | ['the', 'initial', 'tags'] | |
| createTagOnString | Triggers new tag creation | [",", ".", " "] |
| onChangeTags | Fires when tags are added or removed | |
| maxNumberOfTags | The max number of tags that can be entered | infinity |
| onTagPress | Fires when tags are pressed | |
| readonly | Tags cannot be modified | false |
| deleteTagOnPress | Remove the tag when pressed | true |
| containerStyle | Style | |
| style | Style (`containerStyle` alias) | |
| inputContainerStyle | Style | |
| inputStyle | Style | |
| tagContainerStyle | Style | |
| tagTextStyle | Style | |
4 changes: 3 additions & 1 deletion Tags/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Tags extends React.Component {
);
} else if (
text.length > 1 &&
(text.slice(-1) === " " || text.slice(-1) === ",") &&
this.props.createTagOnString.includes(text.slice(-1)) &&
!(this.state.tags.indexOf(text.slice(0, -1).trim()) > -1)
) {
this.setState(
Expand Down Expand Up @@ -119,6 +119,7 @@ class Tags extends React.Component {
Tags.defaultProps = {
initialTags: [],
initialText: " ",
createTagOnString: [",", " "],
readonly: false,
deleteOnTagPress: true,
maxNumberOfTags: Number.POSITIVE_INFINITY
Expand All @@ -127,6 +128,7 @@ Tags.defaultProps = {
Tags.propTypes = {
initialText: PropTypes.string,
initialTags: PropTypes.arrayOf(PropTypes.string),
createTagOnString: PropTypes.array,
onChangeTags: PropTypes.func,
readonly: PropTypes.bool,
maxNumberOfTags: PropTypes.number,
Expand Down

0 comments on commit 62606f4

Please sign in to comment.