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.

Keep open dropdown when using Async with closeOnSelect not working

See original GitHub issue

Hi 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:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
rovolutioncommented, Jan 6, 2020

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-deprecated componentWillReceiveProps method. In the method, it is checking to see if the defaultOptions 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-L103

Within your loadOptions handler method, you can store the fetched options in the local state of your component that render’s Async. This will then trigger a re-render of that component, and you pass those options down from the state into the defaultOptions prop of Async. It will trigger the componentWillReceiveProps and update the defaultOptions. When you select an option, this logic will be triggered in Async. Then when the render() method is executed, this logic in the Async component render method will default to using defaultOptions 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

6reactions
rheydtcommented, May 2, 2019

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:

    <AsyncSelect
        autoload={false}
        cacheOptions={true}
        loadOptions={this.getLoadOptions(loadOptions)}
        value={value ? value.map(this.translateOption) : this.state.value} 
        closeOnSelect={false}
        closeMenuOnSelect={false}
        onSelectResetsInput={false}
        removeSelected={false}
        hideSelectedOptions={false}
        autoBlur={false}
    />
Read more comments on GitHub >

github_iconTop 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 >

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