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.

CreatableSelect doesn't create new options if used with filterOption prop

See original GitHub issue

Hello All,

Thanks a lot for this amazing library.

I am having an issue while using “CreatableSelect” with filterOption prop, which has ‘matchFrom’ value as ‘start’. The issue is that I am not able to create new options.

My Component usage looks like the following:-

const filterConfig = { matchFrom: 'start' }; <CreatableSelect isMulti isClearable={false} openMenuOnClick={false} value={value} options={options} filterOption={createFilter(filterConfig)} className={className} classNamePrefix={classNamePrefix} onChange={onChange} />

If I remove the filterOption prop, it works absolutely fine. Am I missing something here? Any help is greatly appreciated.

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
Rall3ncommented, Apr 2, 2019

You have to wrap the function created by createFilter into another function which checks if the option is the Create ... option.


const customFilter = createFilter({ matchFrom: 'start' });

/* ... */

<CreatableSelect
    { ... }
    filterOptions={(option, rawInput) => {
        // Data says its new so we return true.
        if (option.data.__isNew__) return true;
        
        // Filter using the filter function
        return customFilter(option, rawInput);
    }}
/>

CodeSandbox

0reactions
Anuj16commented, Apr 10, 2020

@Rall3n I had raised a pull request to fix this in repository properly instead of having a workaround. That’s why kept this issue open. But looks like it’s going to take time. So closing this now. Would hope that the pull request gets merged sometime soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Select Creatable "no options" instead of "create"
To solve this, your custom filters must retrun "undefined" in order to "tell" to the <CreatableSelect /> component that there is no such...
Read more >
Advanced
React-Select exports a createFilter function that returns a filterOption method. ... Below is an example of how you could use the createFilter function...
Read more >
Programmatically Add New Options To Dropdown ... - YouTube
In this video, I will show you how to programmatically add a new item to the select list using react select creatable. React...
Read more >
React Autocomplete component - Material UI
The component exposes a factory to create a filter method that can be provided to the filterOptions prop. You can use it to...
Read more >
React Select Advanced Options
We can make a multi-select dropdown that has sortable entries. ... We use the SortableSelect component with a few props. We have the...
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