fmoo / react-typeahead

Pure react-based typeahead and typeahead-tokenizer
ISC License
677 stars 232 forks source link

allowCustomValues PropType requires Number but README says Boolean #246

Open jacobsmith opened 6 years ago

jacobsmith commented 6 years ago

Hello,

Thanks for this library! It's been very easy to pull down and get integrated. I did run into one issue:

The current README states that allowCustomValues is a boolean prop that can be passed in ( https://github.com/fmoo/react-typeahead#propsallowcustomvalues ).

However, when I have that set to false, I see the following in my console:

Warning: Failed prop type: Invalid prop `allowCustomValues` of type `boolean` supplied to `Typeahead`, expected `number`.
    in Typeahead (created by Typeahead)
    in Typeahead (created by ConnectedField)
    in ConnectedField (created by Connect(ConnectedField))
    in Connect(ConnectedField) (created by Field)
    ...

I'd be more than happy to update documentation, but I wanted to check first what the intended use case is. My first impression was that if my list contains ['foo', 'bar'] and I type fooa and click away, the onBlur would set it back to empty (because I want to disallow entries that are not in the list). I'm not seeing that behavior, so figured I can write up some documentation with the results of this thread.

Thanks!

jacobsmith commented 6 years ago

Due to some other business requirements, I ended up using https://github.com/reactjs/react-autocomplete instead. To achieve the same requirement of users selecting from the list, I implemented a validation of:

Typeahead.validateSelectedIsOneOf = (items, display) => {
  return function(value) {
    if (items.map((item) => display(item)).indexOf(value) < 0) {
      return 'Please select from the list';
    }

    // ReduxForm expects "undefined" explicitly if no error is to be raised
    return undefined; // eslint-disable-line no-undefined
  };
};

It may or may not be useful to any future person who finds this issue.

I will leave the issue open as it still seems like either the documentation or the code is slightly mismatched, but feel free to close it if any maintainer sees fit.

Thanks!