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.

fireEvent.focus should be discouraged

See original GitHub issue

Describe the feature you’d like:

Discourage fireEvent.focus(element)

Suggested implementation:

Prefer element.focus()

Describe alternatives you’ve considered:

Don’t use existing API or call element.focus() internally.

Teachability, Documentation, Adoption, Migration Strategy:

fireEvent.focus(element) will not move the focus to the element i.e. document.activeElement !== element. element.focus() will result in document.activeElement === element and dispatch the focus event. fireEvent.focus will also work on non-interactive elements whereas element.focus does not.

Showcase of fireEvent vs imperative focus

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

4reactions
Gpxcommented, Jun 26, 2019

How would it look like? user-event tries to mimic what a user does. AFAIK users can’t give focus to an element. They have to click on it or use tab

3reactions
kentcdoddscommented, Jun 26, 2019

That’s a fair point. Maybe @eps1lon’s original suggestion is the best we can do. Recommend that people use .focus() on the dom node rather than fireEvent.focus.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Considerations for fireEvent | Testing Library
If an element is focused, a focus event is dispatched, the active element in the document changes, and the previously focused element is...
Read more >
How to test which input has the focus when tab button is pressed
I have two inputs. When input1(with autocomplete functionality) is in focus, clicking the Tab button should either auto fill input1 with a text ......
Read more >
How to use the @testing-library/dom.fireEvent.focus function ...
To help you get started, we've selected a few @testing-library/dom.fireEvent.focus examples, based on popular ways it is used in public projects.
Read more >
Improving React Testing Library tests | Alex Khomenko
Focus on testing from the user's point of view and avoidance of ... Properly written tests can not only help to prevent regressions...
Read more >
Testing User Interfaces For Beginners - Joy of Code
You can use tests to prevent people from submitting code in a pull request ... I'm going to focus on testing and giving...
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