Keep open dropdown when using Async with closeOnSelect not working
See original GitHub issueHi guys,
I want to keep open drop-down menu of search when searching users/lists from with Select.Async
after selecting option from drop-down.
I’ve seen similar issues and as @JedWatson given suggestions here https://github.com/JedWatson/react-select/issues/1542#issuecomment-328919546, I’ve tried to do the same but no luck.
here is code which I’m using:
getList(input) {
if (!input) {
return Promise.resolve({ options: [] });
}
return axios.get(`http://localhost:4000/api/v1/search?search=${input}`)
.then(response => {
this.setState({
searchedOptions: response.data.ideas
})
return { options: response.data.ideas };
})
}
<Select.Async
closeOnSelect={false}
onSelectResetsInput={false}
backspaceRemoves={true}
value={this.state.value}
onChange={this.onChange}
onValueClick={this.gotoItem}
valueKey="id"
labelKey="title"
loadOptions={this.getList}
noResultsText={'No result found :('}
cache={false}
/>
Can any one can tell me how to keep open drop-down menu with Async after selecting option from it? Any help would be appreciated 🙏
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Autoclose dropdown menu problem with ng-select
What I want is: Open the drop down, click anywhere in the dropdown menu and the menu will not close, click outside of...
Read more >Advanced - React Select
React Select. A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete, async and creatable support. Star.
Read more >async function - JavaScript - MDN Web Docs - Mozilla
Use of async and await enables the use of ordinary try / catch blocks around asynchronous code. Note: The await keyword is only...
Read more >Angular ng-select - npm
Can be used for loading more items in chunks. Methods. Name, Description. open, Opens the select dropdown panel. close, Closes the select ......
Read more >Tagify - Tags input Component - GitHub Pages
If tried to select all text and delete everything, readonly tags will remain. When a textarea already has mixed-content and it wasn't pre-configured...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I figured out a work-around for this (though it relies on deprecated code that will probably be removed in the near future)
If you examine the source-code for the
Async
component, you can see that it currently uses the now-deprecatedcomponentWillReceiveProps
method. In the method, it is checking to see if thedefaultOptions
prop has changed. If it has, it will update the local state value that holds the default options: https://github.com/JedWatson/react-select/blob/master/packages/react-select/src/Async.js#L97-L103Within your
loadOptions
handler method, you can store the fetched options in the local state of your component that render’sAsync
. This will then trigger a re-render of that component, and you pass those options down from the state into thedefaultOptions
prop ofAsync
. It will trigger thecomponentWillReceiveProps
and update the defaultOptions. When you select an option, this logic will be triggered inAsync
. Then when therender()
method is executed, this logic in the Async component render method will default to usingdefaultOptions
to populate the options list.For reference, I created a sandbox: https://codesandbox.io/s/react-codesandboxer-example-nxrzu?fontsize=14&hidenavigation=1&theme=dark
I also have this issue with Async. Although the dropdown stays open, the options clear (because the input clears), defeating the purpose of leaving it open at all.
Have tried setting a bunch of props I’ve seen mentioned in various issues: