explicitly call .blur() on select?
See original GitHub issueWe’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:
- Created 7 years ago
- Reactions:6
- Comments:6 (2 by maintainers)
Top 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 >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
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.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!