reactjsreact-bootstrap-typeahead

Add value to props when no matches found with React Bootstrap Typeahead


With React Bootstrap Typeahead, if there is no record found and display "no matches found", is it possible I can add that value to the selected props when I click enter?

enter image description here


Solution

  • You can use the allowNew prop to add arbitrary items to the selections:

    <Typeahead
      allowNew
      options={[...]}
      selected={[...]}
    />
    

    When users enter a string that isn't found in the set of options, they'll be presented with a menu option giving them the ability to add the text they've entered as a selection:

    enter image description here

    Here's a working example: https://codesandbox.io/s/rbt-custom-selections-18piu