Skip to content

Commit aeb08cf

Browse files
committed
Refactor soft keyboard support to use existing delimiters option
1 parent 3f763b3 commit aeb08cf

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Refactored event handlers and callbacks to use `on` prefixes
1414
- Refactored `classNames` option to avoid creating new and merging objects for each top-level props change
1515
- Refactored `deleteTag` method so it no longer clears the input text when a tag is removed
16+
- Refactored `delimiters` option to be an array of `KeyboardEvent.key` values
1617
- Removed `clearInputOnDelete` option
1718
- Removed `autofocus` option
1819
- Removed `delimiterChars` option

README.md

+1-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ ReactDOM.render(<App />, document.getElementById('app'))
8585
- [`removeButtonText`](#removeButtontext-optional)
8686
- [`autoresize`](#autoresize-optional)
8787
- [`delimiters`](#delimiters-optional)
88-
- [`delimiterChars`](#delimiterchars-optional)
8988
- [`minQueryLength`](#minquerylength-optional)
9089
- [`maxSuggestionsLength`](#maxsuggestionslength-optional)
9190
- [`classNames`](#classnames-optional)
@@ -151,10 +150,6 @@ Boolean parameter to control whether the text-input should be automatically resi
151150

152151
Array of keys matching `KeyboardEvent.key` values. When a corresponding key is pressed it will trigger tag selection or creation. Defaults to `['Enter', 'Tab']`.
153152

154-
#### delimiterChars (optional)
155-
156-
Array of literal characters. When a corresponding character is entered it will trigger tag selection or creation. Defaults to `[',', ';']`.
157-
158153
#### minQueryLength (optional)
159154

160155
Minimum query length required to show the suggestions list. Defaults to `2`.
@@ -296,7 +291,7 @@ To see all changes refer to [the changelog](CHANGELOG.md).
296291
- React 16.5 or above is now required.
297292
- Event handlers and callbacks have been renamed to use `on` prefixes, e.g. the `handleAddition()` callback should now be called `onAddition()`.
298293
- The `delimiters` option is now an array of `KeyboardEvent.key` values and not `KeyboardEvent.keyCode` codes, e.g. `[13, 9]` should now be written as `['Enter', 'Tab']`. See https://keycode.info/ for more information.
299-
- The `delimiterChars` option is now an array of literal characters, e.g. `[',', ';']`.
294+
- The `delimiterChars` option has been removed, use the `delimiters` option instead.
300295
- The `placeholder` option has been renamed `placeholderText`
301296
- The `clearInputOnDelete` option has been removed and is now the default behaviour
302297
- The `autofocus` option has been removed.

lib/ReactTags.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,14 @@ class ReactTags extends React.Component {
112112
this.props.onInput(query)
113113
}
114114

115-
const lastChar = query.length === this.state.query.length + 1 ? query.slice(-1) : null
116-
117-
if (lastChar && this.props.delimiterChars.indexOf(lastChar) > -1) {
115+
// NOTE: This test is a last resort for soft keyboards and browsers which do not
116+
// support `KeyboardEvent.key`.
117+
// <https://bugs.chromium.org/p/chromium/issues/detail?id=763559>
118+
// <https://bugs.chromium.org/p/chromium/issues/detail?id=118639>
119+
if (
120+
query.length === this.state.query.length + 1 &&
121+
this.props.delimiters.indexOf(query.slice(-1)) > -1
122+
) {
118123
pressDelimiter.call(this)
119124
} else if (query !== this.state.query) {
120125
const options = getOptions.call(this, query)
@@ -256,7 +261,6 @@ ReactTags.defaultProps = {
256261
autoresize: true,
257262
classNames: CLASS_NAMES,
258263
delimiters: [KEYS.TAB, KEYS.ENTER],
259-
delimiterChars: [',', ';'],
260264
minQueryLength: 2,
261265
maxSuggestionsLength: 6,
262266
allowNew: false,
@@ -275,8 +279,7 @@ ReactTags.propTypes = {
275279
suggestions: PropTypes.arrayOf(PropTypes.object),
276280
suggestionsFilter: PropTypes.func,
277281
autoresize: PropTypes.bool,
278-
delimiter: PropTypes.arrayOf(PropTypes.string),
279-
delimiterChars: PropTypes.arrayOf(PropTypes.string),
282+
delimiters: PropTypes.arrayOf(PropTypes.string),
280283
onDelete: PropTypes.func.isRequired,
281284
onAddition: PropTypes.func.isRequired,
282285
onInput: PropTypes.func,

0 commit comments

Comments
 (0)