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.

explicitly call .blur() on select?

See original GitHub issue

We’re using react-select as one of the many field types in a form, and our form component has the following simple logic to ensure that if any field is set to “Other”, a text field is revealed in which users can fill out their out-of-band choice/reason/etc.

  // autofocus on anything that needs autofocussing.
  componentDidUpdate: function(prevProps, prevState) {
    var afelement = this.refs.autofocus;

    if (afelement) {
      if (document.activeElement) {
        document.activeElement.blur();
      }
      ReactDOM.findDOMNode(afelement).focus();
    }
  },

This works perfectly, except when “Other” is chosen in react-select. In that case, React honours the focus() call in componentDidUpdate, and then react-select immediately steals focus back, which it should not be doing.

Is there a way to tell react-select to stop hogging the limelight?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
divmglcommented, Feb 24, 2018

This is an old issue, but I’d like to see the addition of a blur option or the ability to NOT focus the select when selecting an item.

1reaction
Pomaxcommented, Dec 4, 2020

I updated your code to reflect the situation we had and do not see it acting anomalously anymore, so that looks fixed.

And on a small React note, if you’re already returning a single element (in this case, <div>) no need to wrap it in a fragment (the <>). Fragments are only necessary if you would otherwise be trying to returning a bunch of “loose” elements.

Thanks for following up!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to call a function AFTER blur from input? - Stack Overflow
I'm using jquery-ui datepicker as one of my inputs. If a user blurs from an input, I display a relevant message (e.g. "This...
Read more >
HTMLElement.blur() - Web APIs - MDN Web Docs
The HTMLElement.blur() method removes keyboard focus from the current element. ... onclick="focusInput()">Click me to gain focus</button>
Read more >
TextInput - React Native
Two methods exposed via the native element are .focus() and .blur() that will focus or blur the TextInput programmatically.
Read more >
next/image - Next.js
When using the blur-up placeholder, older browsers before Safari 12 will fallback ... Without the 33vw sizes, the image selected from the server...
Read more >
Tutorial - Formik
5 // Pass the useFormik() hook initial form values and a submit function that will ... bag of form state and helper methods...
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