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.

[v2] Loading indicator disappears once the menu is opened

See original GitHub issue

If we open the menu while Async component is loading the options, loadingIndicator disappears even though loadOptions is not yet completed. noOptionsMessage displayed until the options are loaded but no more loadingIndicator(Even if you open/close the menu, it’s same). There is no indication if the options are still loading.

Although it’s a simple scenario, I couldn’t find a similar bug report. Simple test case forked from the web site: https://codesandbox.io/s/14919k7q4

Would there be an alternative way to fix this problem?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sahibjotsaggucommented, Sep 13, 2018

@Atralbus So the problem is here: https://github.com/JedWatson/react-select/blob/master/src/Async.js#L108

It looks like when you click away from the dropdown, it triggers an onInputChange and since inputValue is "", it sets the isLoading state to false.

I think this is definitely a bug, @jossmac, can you please confirm this?

1reaction
Atralbuscommented, Jan 3, 2019

@matthova I think the best option is to handle loading indicator manually with isLoading prop. And I’m using Select component instead of Async since the loadOptions is causing different problems. I reload options when it’s necessary.

Sample code with RxJS to show how I handle loading in the state;

export default class CompWithSelect extends Component {
  constructor(props: Props) {
    super(props)
    this.state = {
        options: [],
        input: '',
        loading: false
    }
    this.search$ = new Subject()
  }

  componentDidMount() {
    this.search$
    .debounceTime(500)
    .do(() => this.setState({ options: [], loading: true }))
    .switchMap(str => this.props.dispatch(runSimpleProgram(str))
      .scan((acc, curr) => curr.name === 'TaskResult' ? [...acc, ...curr.data] : acc, [])
      .finally(() => this.setState({ loading: false }))
    )
    .subscribe(
      (data) => this.setState({
        options: data.map(({value}) => ({value, label: value}))
      }),
      () => this.setState({ loading: false })
    )
  }

  componentDidUpdate(prevProps: Props) {
    if (/* related props changed */) {
      this.search$.next(this.state.input)
    }
  }

  componentWillUnmount() {
    this.search$.unsubscribe()
  }

  handleInputChange = (input: string) => {
    if (this.state.input !== input) {
      this.setState({input})
      this.search$.next(input)
    }
  }

  handleValuesChange = (options: Array<{value: string}>): void => {
    const values = options
      .map(prop('value'))

    this.props.onValuesChange(values)
  }

  handleFocus = () =>
    isEmpty(this.state.options)
    && this.search$.next(this.state.input)

  render () {
    const { values } = this.props
    const { options, loading } = this.state
    return (
      <div>
        <Creatable
          name='values'
          isMulti
          isLoading={loading}
          value={values.map(v => ({label: v, value: v}))}
          options={options}
          filterOption={() => true} // to prevent react-select filter
          onInputChange={this.handleInputChange}
          onChange={this.handleValuesChange}
          onFocus={this.handleFocus}
          closeMenuOnSelect={false}
          createOptionPosition='first'
          allowCreateWhileLoading
        />
      </div>
    )
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap dropdown menu disappears after clicking toggler-icon
When I click on the menu, all of my appear, but they disappear very quickly after that. I also have to click the...
Read more >
Fix a Spinning Wheel Loading Indicator on iPhone or iPad ...
It looks like a spinning wheel made up of little dashes, and when it has gone haywire it will rotate endlessly, never going...
Read more >
How to manually show and hide loading or spinning image?
Instead of default datasource config/method to load remote data, I am using a custom function to load data and I like to manually...
Read more >
How to show Page Loading div until the page has finished ...
Once the page has completely loaded we set loader's display to none and ... Step 2: Open the .html file you saved then...
Read more >
Apps running in background get closed/refreshed
... bar and when i reopen it from the recents menu, it opens like i am opening ... the icon disappears, i lose...
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