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
Add else block to setSelectionRange check #373
Add else block to setSelectionRange check #373
Conversation
Codecov Report
@@ Coverage Diff @@
## master #373 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 12 12
Lines 376 383 +7
Branches 109 111 +2
=========================================
+ Hits 376 383 +7
Continue to review full report at Codecov.
|
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.
Ideally it would be nice to figure out a way to reproduce in a test, but it sounds fairly difficult without coupling our tests to React again, so I'm fine with this.
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.
This makes sense to me 👍 thanks!
@all-contributors please add @WretchedDade for code and tests |
I've put up a pull request to add @WretchedDade! 🎉 |
🎉 This PR is included in version 12.0.4 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Awesome! Thanks ya'll! |
What:
This fixes #369
Why:
Without this change, when a value is changed programatically as part of a React onChange event, the selectionRange stays at (0, 0) causing the values to be typed in reverse order.
How:
Added an else block to the
setSelectionRange
function that is part oftype
. The conditional already existed to check to see if the value changed programatically and my else adds logic to move the selection range to the end of the input to mimic the behavior of the browser.Checklist:
I attempted to replicate my failing react testing here by using the same format function and setting
event.target.value
when the input event fired. However, the test passed without my change. This leads me to believe that it is a symptom of how the value of an input is controlled by React. To confirm this fixed my issue I had to do the following:npm run build
dist/type.js
to my React project'snode_modules/@testing-library/user-event/dist/type.js
file.