Autofocus Text puts cursor at end instead of beginning
See original GitHub issueDo 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.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (3 by maintainers)

Top Related StackOverflow Question
OK the
jsdomissue is now fixed: https://github.com/jsdom/jsdom/pull/2799 When that is released we can upgrade thejsdomversion to pick up the fix, and re-implement the test which should now be useful.@mmarkelov I think this will be hard to write a test, it seems
jsdomis showing that theselectionStartis0even though in the browser the same code showsselectionStartis the end/length of the text value.