-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Wrong place for cursor in Input with autofocus set to true #12779
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
Comments
@jae-huh Same behavior with a native You need to get a reference on the input with the x.setSelectionRange(0, 0); |
@oliviertassinari If you compare your sandbox with mine on Safari, the difference is that the Material UI Input cursor goes to the start of the input field, and the cursor in the native input goes to the end of the field. With Material UI Input component: The behaviour I expect is that the Material UI Input component should have the cursor at the end of the field like the native behaviour. |
Oh, my bad. It sounds like an issue with React. We don't have any specific handling for the focus logic. |
I would like to draw an attention to this issue one more time because now in 4.9.4 it still exists and stil breaks the expectations (for multiline textfield). Is it possible to make the Material UI multiline TextField component to have the cursor at the end after autofocus not writing ref-boilerplate for every single one of the them? Update: it reproduces for multiline textfield. |
Still seeing this issue here as well. When using autofocus with multiline option for TextField, the cursor is placed at the beginning of the input as opposed to the end. Is there a fix for this planned? |
Still having the issue, any plans on opening it again ? |
Still having this issue. any fix? |
It might be related to #23096. |
Instead of using ref, I used the const handleFocus = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
const lengthOfInput = event.target.value.length;
return event.target.setSelectionRange(lengthOfInput, lengthOfInput);
}; |
I found a solution and it is working fine for me.
|
Expected Behavior
Cursor is shown at the end of the given value when autoFocus is set to true with a value.
Current Behavior
Cursor blinks at the start of the given value
Steps to Reproduce
Link: https://codesandbox.io/s/m3339635nj
Context
I'm currently working on a feature that lets users to edit their messages (similar to the example provided) using Material UI's TextField component.
Your Environment
The text was updated successfully, but these errors were encountered: