New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct focus changes based on mouseDown result #192
Conversation
Codecov Report
@@ Coverage Diff @@
## master #192 +/- ##
==========================================
+ Coverage 97.05% 97.12% +0.06%
==========================================
Files 1 1
Lines 136 139 +3
Branches 35 36 +1
==========================================
+ Hits 132 135 +3
Misses 4 4
Continue to review full report at Codecov.
|
Thank you for this PR. Do you mind adding some tests for this use-case? |
@Gpx Sure thing. Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Thank you :D
🎉 This PR is included in version 8.0.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@kentcdodds Thanks for merging this. Would you add me via all contributors bot, please? 🙏 |
My bad. Sorry I forgot |
@all-contributors please add @ilyamkin for code and tests |
I've put up a pull request to add @ilyamkin! 🎉 |
Because
userEvent.click
should simulate real browsers' behavior, we need to take into account the result of each event.In this particular case if
mouseDown
event haspreventDefault
, it should stop focus event.Here is the source code of Google Chrome Blink for reference (others follow the same convention):
https://chromium.googlesource.com/chromium/blink/+/master/Source/core/input/EventHandler.cpp#972
dispatchMouseEvent
return value means "continue default handling", soswallowEvent
istrue
in case ofpreventDefault
usage.Just below there is call for focus event which is triggered only if
swallowEvent === false
We heavily rely on this case when developing complex components for the design system with focus management.
Another moment is that we probably should use
fireEvent.focus()
instead ofelement.focus()
to also understand ifonFocus
was canceled, but that's for another change (related to scrollbar behavior on focus).