score:3

Accepted answer

I think your problem here comes from your custom filter implementation

This a little bit tricky, because from the docs there is no example of the CreatableSelect with an implementation of custom filter.

To solve this, your custom filters must retrun "undefined" in order to "tell" to the <CreatableSelect /> component that there is no such option.

So here is one option to achieve this :

       const customFilter = (option, searchText) => {
          return option.data.searchfield !== undefined ? option.data.searchfield.toLowerCase().includes(searchText.toLowerCase())
: "undefined"
        };

In this way your CreatableSelect will known if the value was found

Another problem that I noticed in your code is that your renderValue method will return an empty string when it does not find a matching option...not good : if you want the users to create option you have to render it when it will be created...not an empty string.

So replace this by something like :

    const renderValue = (value) => {
      const val = value === "" ? 
                  null : 
                  options.find((obj) => obj.value === input.value);
      return val || {value : value, label: value};
  };

That will create your new option. Of course you can change the label by your own logic.


Related Query

More Query from same tag