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.

onBlur event is being called incorrectly when user is typing

See original GitHub issue

Thanks 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:open
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jackgeekcommented, Aug 29, 2019

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

0reactions
s-yadavcommented, Oct 10, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

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