question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AsyncCreatable + filterOptions breaks create functionality

See original GitHub issue

AsyncCreatable is working well, until I add a custom filterOptions prop. At that point async lookup still works, however the creatable behavior disappears - there is no longer an option to add an unrecognized value.

The custom filter I’m using works as expected with both the Creatable hoc and the base Select component. The issue is only with AsyncCreatable. My filter is just removing options a user previously selected, but which react-select is no longer aware of.

The issue manifests even with a simple filter function that just returns the options unmodified. Here’s a plunker to demonstrate:

https://plnkr.co/edit/KWDD9e2OexIHMiej6ZK2?p=preview

Turns out using an identity function as a filter for a standard Creatable select adds a new “Create option” option on each keystroke - maybe that points to another bug? 😄 While slightly annoying, the main issue described is still observable with the last AsyncCreatable - nothing can be created.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
oomathiascommented, Feb 17, 2017

@bvaughn Oh sorry, I didn’t blame the file… Yup, it has been reversed later.

Yeah, I came out with the same fix, unfortunately, it’s not enough.

@unity The change was made here https://github.com/JedWatson/react-select/pull/1374 Why did you reverse the props override asyncProps <==> creatableProps? Also, reduce seems to do nothing more.

Fix

I updated the demo with the proposed fix, but it’s just a first step, look at my GIF. https://embed.plnkr.co/ik8qaDyOUsa1usQQktaE/

Filtered filterOptions={(i) => i}

filtered

Not filtered no filterOptions

non-filtered

2reactions
bvaughncommented, Feb 17, 2017

Hm. I’m not sure why the order of override properties were reversed since I first created that component.

Anyway, I see. The user’s filterOptions function is passed to both the inner Async and the inner Creatable then later reduced so that the Async props override the Creatable props. This means that Creatable can’t hook into this process like it needs to.

I think one fix would be similar to what we do with onInputChanged:

              <Select
                {...asyncProps}
                {...creatableProps}
                filterOptions={creatableProps.filterOptions}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced - React Select
React-Select exports a createFilter function that returns a filterOption method. ... is creatable, you would also likey want to include the "Create" option....
Read more >
react-select-pre - npm
filterOption : function(Object option, String filter) returns Boolean . Will override matchPos , matchProp , ignoreCase and ignoreAccents ...
Read more >
react-select/CHANGELOG.md - UNPKG
160, - async select now accepts a filterOptions function as a prop [#2822](https://github.com/JedWatson/react-select/pull/2822). 161, - [BREAKING] ...
Read more >
github.com-JedWatson-react-select_-_2017-11-25_09-05-50
filterOption : function(Object option, String filter) returns Boolean . Will override matchPos , matchProp , ignoreCase and ignoreAccents ...
Read more >
React Select Async creatable doesn't save to the state
I am using react select async creatable, the data from api loads correctly and can select it also can create new values but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found