Skip to content
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

[TextField] Cursor position on Chrome after server-side rendering #23096

Closed
2 tasks done
zachbradshaw opened this issue Oct 16, 2020 · 10 comments
Closed
2 tasks done

[TextField] Cursor position on Chrome after server-side rendering #23096

zachbradshaw opened this issue Oct 16, 2020 · 10 comments
Labels
component: text field This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation external dependency Blocked by external dependency, we can’t do anything about it

Comments

@zachbradshaw
Copy link
Contributor

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When clicking the label of an input that has a value, the input's cursor will appear at the beginning of the value. A second click/action is required to move the cursor to the end of the value to edit it.

Expected Behavior 🤔

When the label of a field is clicked, the input's cursor should default to the end of the value, if one exists.

Steps to Reproduce 🕹

Steps:

  1. Go to the TextField demo page
  2. Click on the label of a non-disabled, editable input that has a value.
  3. Notice that the cursor defaults to the beginning of the value, instead of the end.

Context 🔦

We're using Material UI inputs for all of our forms, and are looking to make editing behavior as consistent as possible.

Your Environment 🌎

Tech Version
Material-UI v4.11.0
React 16.13.1
Browser Chrome 86.0.4240.80
TypeScript 4.0.3
@zachbradshaw zachbradshaw added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 16, 2020
@eps1lon
Copy link
Member

eps1lon commented Oct 16, 2020

Thanks for the report 👍

When the label of a field is clicked, the input's cursor should default to the end of the value, if one exists.

This is indeed the behavior for native inputs on pristine inputs. But once the select range changes, clicking the label restores the range.

Restoring is already working with Material-UI inputs. It's just that the range is different for pristine inputs. Though it might be caused by something different (e.g. controlled vs uncontrolled?).

Either way, we need to identify what is responsible for changing the selection range. The actual label-click behavior is working correctly.

@eps1lon eps1lon added bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 16, 2020
@oliviertassinari

This comment has been minimized.

@eps1lon
Copy link
Member

eps1lon commented Oct 17, 2020

Not sure, on Chrome 86 after a hard refresh:

The point is not to force a particular behavior but try to avoid changing the selection range on pristine text fields. We could never reproduce nor we should we override native behavior.

@oliviertassinari
Copy link
Member

It looks like an issue with our documentation, not the component itself. The behaviors are identical on https://codesandbox.io/s/angry-tdd-fh4qq?file=/src/App.js.

@eps1lon
Copy link
Member

eps1lon commented Oct 17, 2020

It looks like an issue with our documentation, not the component itself. The behaviors are identical on codesandbox.io/s/angry-tdd-fh4qq?file=/src/App.js.

Interesting. The demo cloned in codesandbox works correct as well. I also tried https://material-ui.com/components/text-fields/#form-props in an incognito window and had the same issue (suspecting it was auto-fill related).

@eps1lon eps1lon added the docs Improvements or additions to the documentation label Oct 17, 2020
@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 17, 2020

It has something to do with the server-side rendering. NoSsr changes the outcome.

@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 17, 2020

@oliviertassinari
Copy link
Member

I think that we can close, it looks like the native behavior: same on https://getbootstrap.com/docs/4.5/components/forms/#server-side.

@eps1lon
Copy link
Member

eps1lon commented Oct 17, 2020

It has something to do with the server-side rendering.

Yes! There's a difference between <input value="foo" /> in plain HTML and a client-side rendered <input defaultValue="foo" />: https://codesandbox.io/s/serverless-field-jokfq?file=/src/index.js

Related react issues: facebook/react#18404, facebook/react#14904, facebook/react#12762

This is best raised against the React repo. The correct behavior would be to not modify the selection and keep the cursor at the start for mounted inputs. So the opposite of what you would expect.

@eps1lon eps1lon closed this as completed Oct 17, 2020
@oliviertassinari oliviertassinari removed the bug 🐛 Something doesn't work label Oct 17, 2020
@oliviertassinari oliviertassinari changed the title TextField cursor position defaults to beginning of value when input label is clicked [TextField] Cursor position on Chrome after server-side rendering Oct 17, 2020
@zachbradshaw
Copy link
Contributor Author

@eps1lon @oliviertassinari Thanks for taking the time to check this out and for the info about SSR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation external dependency Blocked by external dependency, we can’t do anything about it
Projects
None yet
Development

No branches or pull requests

3 participants