Material-ui: Wrong place for cursor in Input with autofocus set to true

Created on 5 Sep 2018  路  4Comments  路  Source: mui-org/material-ui

  • [x] This is a v1.x issue.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

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

  1. Open the link in browsers other than Chrome.
  2. Toggle the Input component by clicking the button.
  3. See where the cursor blinks in edit mode.

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

| Tech | Version |
|--------------|---------|
| Material-UI | v1.4.3 |
| React | v16.4.2 |

question

Most helpful comment

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.

All 4 comments

@Jae-Huh Same behavior with a native input element.
capture d ecran 2018-09-05 a 08 36 11
https://codesandbox.io/s/38vxvq0kwm

You need to get a reference on the input with the inputRef property and to change the caret position with a DOM API.

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:
screen shot 2018-09-06 at 8 53 39 am

Native input element:
screen shot 2018-09-06 at 8 51 40 am

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chris-hinds picture chris-hinds  路  3Comments

revskill10 picture revskill10  路  3Comments

iamzhouyi picture iamzhouyi  路  3Comments

rbozan picture rbozan  路  3Comments

newoga picture newoga  路  3Comments