Skip to content
This repository was archived by the owner on Nov 20, 2021. It is now read-only.

Commit defc6de

Browse files
author
Ola Holmström
committed
Fix examples and update readme.
1 parent cd15a2f commit defc6de

File tree

8 files changed

+94
-63
lines changed

8 files changed

+94
-63
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 3.14.1 (2017-02-11)
2+
3+
* Update README and fix examples.
4+
15
### 3.14.0 (2016-12-07)
26

37
* Add `inputValue` and `onChangeInput` which allows control of input.

README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class Example extends React.Component {
9797
Install [`react-input-autosize`](https://github.com/JedWatson/react-input-autosize) and change the `renderInput` prop to:
9898

9999
```js
100-
function autosizingRenderInput (props) {
100+
function autosizingRenderInput ({addTag, ...props}) {
101101
let {onChange, value, ...other} = props
102102
return (
103103
<AutosizeInput type='text' onChange={onChange} value={value} {...other} />
@@ -111,24 +111,42 @@ Use [`react-autosuggest`](https://github.com/moroshko/react-autosuggest) and cha
111111
something like:
112112

113113
```js
114-
function autosuggestRenderInput (props) {
114+
function autosuggestRenderInput ({addTag, ...props}) {
115+
const handleOnChange = (e, {newValue, method}) => {
116+
if (method === 'enter') {
117+
e.preventDefault()
118+
} else {
119+
props.onChange(e)
120+
}
121+
}
122+
123+
const inputValue = (props.value && props.value.trim().toLowerCase()) || ''
124+
const inputLength = inputValue.length
125+
126+
let suggestions = states().filter((state) => {
127+
return state.name.toLowerCase().slice(0, inputLength) === inputValue
128+
})
129+
115130
return (
116131
<Autosuggest
117132
ref={props.ref}
118133
suggestions={suggestions}
119134
shouldRenderSuggestions={(value) => value && value.trim().length > 0}
120135
getSuggestionValue={(suggestion) => suggestion.name}
121136
renderSuggestion={(suggestion) => <span>{suggestion.name}</span>}
122-
inputProps={props}
137+
inputProps={{...props, onChange: handleOnChange}}
123138
onSuggestionSelected={(e, {suggestion}) => {
124-
this.refs.tagsinput.addTag(suggestion.name)
139+
addTag(suggestion.name)
125140
}}
141+
onSuggestionsClearRequested={() => {}}
142+
onSuggestionsFetchRequested={() => {}}
126143
/>
127144
)
128145
}
129146
```
130147

131-
A working example can be found in [`example/components/autocomplete.js`](https://github.com/olahol/react-tagsinput/blob/master/example/components/autocomplete.js).
148+
A working example can be found in
149+
[`example/components/autocomplete.js`](https://github.com/olahol/react-tagsinput/blob/master/example/components/autocomplete.js).
132150

133151
##### How do I control the value of the input box?
134152

example/bundle.js

Lines changed: 45 additions & 34 deletions
Large diffs are not rendered by default.

example/components/autocomplete.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ class AutocompleteExample extends React.Component {
7070
}
7171

7272
render () {
73-
const autocompleteRenderInput = (props) => {
74-
delete props.addTag
75-
73+
function autocompleteRenderInput ({addTag, ...props}) {
7674
const handleOnChange = (e, {newValue, method}) => {
7775
if (method === 'enter') {
7876
e.preventDefault()
@@ -97,9 +95,9 @@ class AutocompleteExample extends React.Component {
9795
renderSuggestion={(suggestion) => <span>{suggestion.name}</span>}
9896
inputProps={{...props, onChange: handleOnChange}}
9997
onSuggestionSelected={(e, {suggestion}) => {
100-
props.addTag(suggestion.name)
98+
addTag(suggestion.name)
10199
}}
102-
onSuggestionsClearRequested={() => this.setState({tags: []})}
100+
onSuggestionsClearRequested={() => {}}
103101
onSuggestionsFetchRequested={() => {}}
104102
/>
105103
)

example/components/autosize.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class AutosizeExample extends React.Component {
1515
}
1616

1717
render () {
18-
function autosizingRenderInput (props) {
19-
let {onChange, value, addTag, ...other} = props
18+
function autosizingRenderInput ({addTag, ...props}) {
19+
let {onChange, value, ...other} = props
2020
return (
2121
<AutosizeInput type='text' onChange={onChange} value={value} {...other} />
2222
)

example/components/email.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ class EmailExample extends React.Component {
1313
}
1414

1515
render () {
16-
var EMAIL_VALIDATION_REGEX = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
16+
var EMAIL_VALIDATION_REGEX = /^[-a-z0-9~!$%^&*_=+}{'?]+(\.[-a-z0-9~!$%^&*_=+}{'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
1717

1818
return (
19-
<TagsInput
20-
value={this.state.tags}
21-
addKeys={[9, 13, 32, 186, 188]} // tab, enter, space, semicolon, comma
22-
onlyUnique={true}
23-
addOnPaste={true}
24-
validationRegex={EMAIL_VALIDATION_REGEX}
25-
pasteSplit={data => {
26-
return data.replace(/[\r\n,;]/g, ' ').split(' ').map(d => d.trim())
27-
}}
28-
onChange={::this.handleChange}
29-
/>
19+
<TagsInput
20+
value={this.state.tags}
21+
addKeys={[9, 13, 32, 186, 188]} // tab, enter, space, semicolon, comma
22+
onlyUnique
23+
addOnPaste
24+
validationRegex={EMAIL_VALIDATION_REGEX}
25+
pasteSplit={data => {
26+
return data.replace(/[\r\n,;]/g, ' ').split(' ').map(d => d.trim())
27+
}}
28+
onChange={::this.handleChange}
29+
/>
3030
)
3131
}
3232
}
3333

34-
export default EmailExample;
34+
export default EmailExample

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-tagsinput",
3-
"version": "3.14.0",
3+
"version": "3.14.1",
44
"description": "Highly customizable React component for inputing tags",
55
"main": "react-tagsinput.js",
66
"peerDependencies": {
@@ -16,11 +16,9 @@
1616
"babel-preset-react": "^6.5.0",
1717
"babel-preset-stage-0": "^6.5.0",
1818
"babel-register": "^6.8.0",
19-
"css-loader": "^0.26.1",
2019
"isparta": "^4.0.0",
2120
"jsdom": "^7.0.2",
2221
"mocha": "^2.3.3",
23-
"postcss-loader": "^1.2.2",
2422
"react": "15.x.x",
2523
"react-addons-test-utils": "^15.0.0",
2624
"react-autosuggest": "^8.0.0",

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ class TagsInput extends React.Component {
180180

181181
if (onlyUnique) {
182182
tags = uniq(tags)
183-
tags = tags.filter(tag => value.every(currentTag => this._getTagDisplayValue(currentTag) !== this._getTagDisplayValue(tag)))
183+
tags = tags.filter(tag => value.every(currentTag =>
184+
this._getTagDisplayValue(currentTag) !== this._getTagDisplayValue(tag))
185+
)
184186
}
185187

186188
tags = tags.filter(tag => validationRegex.test(this._getTagDisplayValue(tag)))

0 commit comments

Comments
 (0)