Option to blur input box on change
See original GitHub issueGreat lib, thx. However I want our single-select box to blur when an option is selected rather than remain focused with cursor in the input. To accomplish this right now it seems I not only have to ...querySelector('.Select-input input').blur()
in the onChange
handler but I have to put it in a timeout. Is there an easier way to accomplish this and/or get it as an option?
Issue Analytics
- State:
- Created 9 years ago
- Reactions:2
- Comments:14 (1 by maintainers)
Top Results From Across the Web
input change event triggered on blur - javascript - Stack Overflow
when I change the value of a text input and then blur that input it triggers the input change event again. How can...
Read more >Element: blur event - Web APIs | MDN
The blur event fires when an element has lost focus. The event does not bubble, but the related focusout event that follows does...
Read more >The difference between onBlur vs onChange for React text ...
onBlur is fired when you have moved away from an object without necessarily having changed its value. onChange is only called when you...
Read more >onblur Event - W3Schools
The onblur event occurs when an element loses focus. The onblur event is often used on input fields. The onblur event is often...
Read more >Focusing: focus/blur - The Modern JavaScript Tutorial
The focus event is called on focusing, and blur – when the element loses the focus. Let's use them for validation of an...
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
I think this issue should be re-opened as well. I am currently rendering a
React-Select
component in aFormik
form, and was running into issues because there wasn’t an obvious way to run theReact-Select
onBlur
afteronChange
.To be more specific, the form has a validation that says the input field is a required field. To ensure this, my
onBlur
handler sets theFormik
field totouched
which triggers the validation handler to run and surface the error:When I do select an option I am setting the
Formik
field manually in the SelectonChange
:Lastly, I also have a design requirement that the dropdown loses focus on selection, which is easily handled with the
blurInputOnSelect
flag.My issue is that enabling the
blurInputOnSelect
forces theonBlur
handler to run before theonChange
handler, so the validation error was surfacing even though the field was valid. After much trial and error, the only solution I could think of was to usesetTimeout
to force theFormik
handler to get added to behind theonChange
handler in the event queue.This solution is not ideal as it is best practice to avoid async functions in react outside of hooks. Is it possible to introduce a
blurOnChange
flag or modify theblurOnInputSelect
flag to mimic this behavior? Is there a reason theonBlur
has to occur beforeonChange
?@JedWatson if you have a moment I would greatly appreciate your insight on this matter.
Hey there! maybe it can help for material-ui 1.. user but can work for others too. I use an
Input
and add theReact-Select
component ininputComponent
of Input props. Then add yourref
to your select. You can now access it with :this.refs.select.input.input.blur()
( twice input here, cause the first one ref theAutosizeInput
and the second one is the input Element) Hope it help someone.