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
Autofocus Text puts cursor at end instead of beginning #14125
Comments
|
Want to look into a fix? |
|
Sure thing, thanks for confirming. I'll look into it. |
|
@Matthew-Goldberg I just tried to figure out what is wrong with it, but I don't have any ideas with it. So if you stack on it - you could try this - works in all modern browsers |
|
Just to narrow it down, v16.2.0 works and v16.3.0 doesn't, so it's somewhere in there. |
|
bisected to this commit |
|
Thank you @chasestarr that makes sense. It also happens in plain HTML the cursor will be at the end if you set the value using script |
|
@mmarkelov I think this will be hard to write a test, it seems |
|
OK the |
|
(#14171) |
Hum, for me it depends on the use case. But the thing is in React 16 the behavior changed without any info about it, so for me it's just a regression until it's proven that it's the desired effect for most use cases. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
In React 16, a text input with a value and autofocus will set the cursor at the end of the input.
<input autoFocus={true} type="text" defaultValue="4444" />If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
See the React 16 repro here: https://codepen.io/matthewg0/pen/XymjYo
What is the expected behavior?
In React 15, and in plain HTML, the behavior is that the cursor is placed at the start of the input.
React 15: https://codepen.io/matthewg0/pen/NEGRzv
Plain HTML: https://codepen.io/matthewg0/pen/wQKoap
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Reproduces as of React 16. Worked as expected in React 15.
The text was updated successfully, but these errors were encountered: