Skip to content

Commit b823faa

Browse files
Merge pull request #88 from ajmas/issue-87-delimeters-non-us-keyboards
Fixes issue #87 - delimiters on non US keyboards
2 parents e4006a3 + 8201a77 commit b823faa

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ React.render(<App />, document.getElementById('app'))
7373
- [`autofocus`](#autofocus-optional)
7474
- [`autoresize`](#autoresize-optional)
7575
- [`delimiters`](#delimiters-optional)
76+
- [`delimiterChars`](#delimitersChars-optional)
7677
- [`minQueryLength`](#minquerylength-optional)
7778
- [`maxSuggestionsLength`](#maxsuggestionslength-optional)
7879
- [`classNames`](#classnames-optional)
@@ -122,6 +123,10 @@ Boolean parameter to control whether the text-input should be automatically resi
122123

123124
Array of integers matching keyboard event `keyCode` values. When a corresponding key is pressed, the preceding string is finalised as tag. Default: `[8, 13]`.
124125

126+
#### delimtersChars (optional)
127+
128+
Array of characters matching keyboard event `key` values. This is useful when needing to support a specific character irrespective of the keyboard layout. Note, that this list is separate from the one specified by the `delimeters` option, so you'll need to set the value there to `[]`, if you wish to disable those keys. Example usage: `delimeterChars={[',', ' ']}`. Default: `[]`
129+
125130
#### minQueryLength (optional)
126131

127132
How many characters are needed for suggestions to appear. Default: `2`.

lib/ReactTags.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ class ReactTags extends React.Component {
5858

5959
handleKeyDown (e) {
6060
const { query, selectedIndex } = this.state
61+
const { delimiters, delimiterChars } = this.props
6162

6263
// when one of the terminating keys is pressed, add current query to the tags.
63-
if (this.props.delimiters.indexOf(e.keyCode) !== -1) {
64+
if (delimiters.indexOf(e.keyCode) !== -1 || delimiterChars.indexOf(e.key) !== -1) {
6465
(query || selectedIndex > -1) && e.preventDefault()
6566

6667
if (query.length >= this.props.minQueryLength) {
@@ -191,6 +192,7 @@ ReactTags.defaultProps = {
191192
autofocus: true,
192193
autoresize: true,
193194
delimiters: [KEYS.TAB, KEYS.ENTER],
195+
delimiterChars: [],
194196
minQueryLength: 2,
195197
maxSuggestionsLength: 6,
196198
allowNew: false,
@@ -205,6 +207,7 @@ ReactTags.propTypes = {
205207
autofocus: PropTypes.bool,
206208
autoresize: PropTypes.bool,
207209
delimiters: PropTypes.arrayOf(PropTypes.number),
210+
delimiterChars: PropTypes.arrayOf(PropTypes.string),
208211
handleDelete: PropTypes.func.isRequired,
209212
handleAddition: PropTypes.func.isRequired,
210213
handleInputChange: PropTypes.func,

0 commit comments

Comments
 (0)