Skip to content

Using suggestions in conjunction with allowNew causes crashes #171

@edvinh

Description

@edvinh

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:

GIF Link

How to reproduce it:

  1. Use the react-tags component with suggestions and the allowNew prop
  2. Start typing something included in the suggestions
  3. Highlight a suggestion with the arrow keys
  4. Continue typing something not included in the suggestions
  5. 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)}
/>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions