-
Notifications
You must be signed in to change notification settings - Fork 164
Closed
Labels
Description
I've discovered a bug occurring in some cases when highlighting a suggestion and continue typing without selecting it (and then pressing Enter), shown here:
How to reproduce it:
- Use the
react-tagscomponent with suggestions and theallowNewprop - Start typing something included in the suggestions
- Highlight a suggestion with the arrow keys
- Continue typing something not included in the suggestions
- Submit it with Enter
Stacktrace:
Uncaught TypeError: Cannot read property 'disabled' of undefined
at ReactTags.addTag (ReactTags.js:152)
at ReactTags.handleDelimiter (ReactTags.js:118)
at ReactTags.handleKeyDown (ReactTags.js:80)
at HTMLUnknownElement.callCallback (react-dom.development.js:362)
at Object.invokeGuardedCallbackDev (react-dom.development.js:411)
at invokeGuardedCallback (react-dom.development.js:466)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:480)
at executeDispatch (react-dom.development.js:612)
at executeDispatchesInOrder (react-dom.development.js:637)
at executeDispatchesAndRelease (react-dom.development.js:743)
The issue lies in that the selectedIndex state in ReactTags.js isn't reset when the user continues to type, causing the suggestions list to update and in turn return undefined when accessing the list's index on submit. I haven't had much more time looking at it -- though it seems like a trivial fix and I might submit a PR myself if I find the time.
I've tested this on both the 6.0 and master branch by using the provided example, adding only the allowNew prop shown below.
<Tags
tags={this.state.tags}
suggestions={this.state.suggestions}
+ allowNew
handleDelete={this.handleDelete.bind(this)}
handleAddition={this.handleAddition.bind(this)}
/>