Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit 3514a0b

Browse files
authored
Removed interim fix for tag field (#581)
* Fixes #568 - removed interim delimiter fix for tag field * DELIMITERS as const
1 parent e93942a commit 3514a0b

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"react-ga": "^2.1.2",
9292
"react-helmet": "^5.0.3",
9393
"react-router": "^3.0.0",
94-
"react-tag-autocomplete": "^5.3.0",
94+
"react-tag-autocomplete": "^5.4.0",
9595
"shx": "^0.2.1",
9696
"superagent": "^3.3.0",
9797
"url": "^0.11.0",

pages/add/form/detail-info-fields.js

+4-31
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import ReactTags from 'react-tag-autocomplete';
33
import validator from './validator';
44
import Service from '../../../js/service';
55

6+
const DELIMITERS = [9,13,188]; // keycodes for tab,enter,comma
7+
68
let Tags = React.createClass({
79
getInitialState() {
810
return {
@@ -22,35 +24,6 @@ let Tags = React.createClass({
2224
.catch((reason) => {
2325
console.error(reason);
2426
});
25-
26-
this.shimTagDelimiter();
27-
},
28-
shimTagDelimiter: function() {
29-
// The ReactTags component for some reason does not
30-
// do tag seperation on anything except "enter" which is
31-
// not an intuitive key when you're on a single-line input.
32-
// We are adding a hack here to force delimiting on comma.
33-
// Ideally, this hack can be taken out again after
34-
// https://github.com/i-like-robots/react-tags/issues/76 is addressed.
35-
try {
36-
const reactTags = this.reactTags;
37-
const trueInput = reactTags.input.input;
38-
const forceKey = reactTags.handleKeyDown.bind(reactTags);
39-
40-
trueInput.addEventListener("keyup", evt => {
41-
// did we type a comma?
42-
const key = evt.key;
43-
if (key === ',') {
44-
// remove the comma and type an enter instead
45-
const { query, selectedIndex } = reactTags.state;
46-
reactTags.state.query = query.substring(0, query.length-1);
47-
forceKey({ keyCode: 13, preventDefault: ()=>{} });
48-
}
49-
});
50-
51-
} catch (e) {
52-
console.warning("Could not set up comma-delimiting for tags");
53-
}
5427
},
5528
updateTags: function(tags) {
5629
this.setState({ tags }, () => {
@@ -80,15 +53,15 @@ let Tags = React.createClass({
8053
}).filter(suggestion => !!suggestion);
8154
},
8255
render: function() {
83-
8456
return <ReactTags
8557
ref={e => this.reactTags = e}
8658
tags={this.state.tags}
8759
suggestions={this.getFilteredSuggestions()}
8860
allowNew={true}
61+
autofocus={false}
62+
delimiters={DELIMITERS}
8963
handleDelete={(...args) => this.handleDelete(...args) }
9064
handleAddition={(...args) => this.handleAddition(...args) }
91-
autofocus={false}
9265
classNames={{
9366
root: `react-tags form-control d-flex flex-column flex-sm-row`,
9467
selectedTag: `selected-tag btn btn-sm mr-sm-2 my-1`,

0 commit comments

Comments
 (0)