onBlur event is being called incorrectly when user is typing
See original GitHub issueThanks very much for this library.
Problem
The NumberFormat component is calling the onBlur
event handler incorrectly. I can also reproduce this in my own project. I can also reproduce this using “@testing-library/react” and “@testing-library/user-event” in this sandbox EDITED (to update all dependencies in the sandbox to the latest versions)
Expected Behaviour
The NumberFormat component should not call onBlur
in response to the user typing when they have not tabbed out.
Experienced Behaviour
onBlur
is called while typing “123”
It would be much appreciated if you can take a look at the issue.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
onblur event is not firing - javascript - Stack Overflow
To have Onblur on an element it should receive focus first, Div elements don't receive focus by default. You can add tabindex="0"
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 >Onblur issue on text box autocomplete..?
My problem is i am using blur event whenever i type some thing in that autocomplete text box i am selecting a autocomplete...
Read more >Examples on How onblur Event Works in JavaScript - eduCBA
The onblur event gets fired when the user navigates to the input field and as soon as leaves the element i.e. the element...
Read more >blur | Cypress Documentation
Blur a textarea after typing. cy.get('[name="comment"]').focus ...
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
Hi there, I am a colleague of @rohiniseetul working with her on this issue. Together we discovered that this is caused by a bug in JSDOM which is used by Jest. JSDOM is incorrectly sending focus and blur events when you call the focus() method on an input element.
In the browser if you call input.focus() and then call input.focus() again you will get at most one focus event and no blur events for input. But in JSDOM there is a bug which will cause you to get two focus and one blur events for input.
We have found a workaround to fix this problem in JSDOM and we are going to share it with the JSDOM team. I will paste a link to the issue here when I have it.
However we have had a good look at the source code of number-format.js and we cannot see any good reason for the .focus to be continually called as clearly the input already has focus or the user could not be typing in it. What is the reason for this?
Kind regards, Jack
I don’t think this is picked. Happy to receive a PR for this. This is the place to look for. https://github.com/s-yadav/react-number-format/blob/master/src/utils.js#L112