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 LOSES FOCUS WHEN OPTIONS ARRIVES FROM API

See original GitHub issue

I am using the async-Creatable field which looks like the below. When options arrive from the API call, Select Field losses focus from the text-area and if I click the text area again it will clear text-field. I saw this suggestion

You can fix this by either moving the Input definition outside render(), or commenting out the inputValue/onInputChange props.

But it’s not working for me.

 <AsyncCreatable
          components={selectComponents}
          name={name}
          styles={{ menuPortal: base => ({ ...base, zIndex: 9999 }) }}
          menuPortalTarget={shouldPortal ? document.body : null}
          onChange={onChange}
          onCreateOption={handleCreate}
          closeMenuOnScroll
          value={value}
          formatCreateLabel={inputVal => `${createLabel || 'create'} "${inputVal}"`}
          isValidNewOption={isValidNewOption}
          loadOptions={promiseOptions}
          {...selectProps}
          {...restInput}
        />
    const selectComponents = ({
      Control: props => <ControlComponent controlProps={props} label={label} required={required} value={value} name={name} />,
      ValueContainer,
      Menu,
      Option: props => <Option optionProps={props} rest={rest} />
    });

Please let me know how can I fix this problem .

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
Rall3ncommented, Nov 18, 2019

@somilkhandelwal Try moving your selectComponents variable outside of your render function, preferably outside of your component.

0reactions
somilkhandelwalcommented, May 10, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

React-Select Custom Input Losing Focus - Stack Overflow
I've built my input in such a way that when the select is typed into, a debounced network request fires and then the...
Read more >
API - React Select
A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete and ajax support.
Read more >
API - React Select
Determines whether the "create new ..." option should be displayed based on the current input value, select value and options array. function (....
Read more >
react-select losing focus for custom component "valuecontainer"
I am using the async-Creatable field which looks like the below. When options arrive from the API call, Select Field losses focus from...
Read more >
react-select-legacy - npm
Options should be provided as an Array of Object s, each with a value and ... props can be a mix of Async,...
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