fix: handle cursor position on controlled component #765
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What:
Another try to fix handling of cursor position.
Closes #758
Why:
Programmatic changes of an element's value property move the cursor to the end of the value.
Changes in the UI don't.
Our implementation to intercept changes on the property setter allows to differ our "UI" changes from "programmatic" ones.
But this kinda conflicts with React's value tracking because somehow in our test environment React restores the previous value before applying the new value on controlled components.
Which of course we pick up as programmatic changes.
In the browser the updates are batched so that there is no programmatic change of value.
How:
Track the changes on the input event.
If the value is only reset to the old one and then subsequently to the new one, we reapply the correct selection range.
As this might overwrite legitimate changes to the selection range, we should further investigate how we could make React batch the changes like it does in the browser.
Checklist:
Note that we had test cases simulating a controlled element that behaved different than an element controlled by React.
Those have been moved to our React tests.