question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cursor jumps to the start of input when changing input type

See original GitHub issue
  • [x ] The issue is present in the latest release.
  • [ x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Cursor jumps to the start of input when changing input type

Expected Behavior 🤔

Cursor preserves its position when changing input type

Steps to Reproduce 🕹

Steps:

  1. Create textfield with password input type and visibility toggler like this: https://material-ui.com/components/text-fields/#input-adornments
  2. Input some text
  3. Click password visibility icon button
  4. Cursor jumps to the start of input

Context 🔦

Your Environment 🌎

Version 90.0.4430.85 (Official Build) (x86_64)

`npx @material-ui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @material-ui/envinfo` goes here.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
juliomoreiracommented, May 2, 2021

I found a workaround to this problem by calling preventDefault() on the onMouseUp event as well.

https://codesandbox.io/s/admiring-bash-htted?file=/pages/index.js

I wasn’t able to track down this bug but I don’t think it’s React fault since it works properly on CRA.

Hope it helps

1reaction
jiblett1000commented, Dec 5, 2022

I found a workaround to this problem by calling preventDefault() on the onMouseUp event as well.

https://codesandbox.io/s/admiring-bash-htted?file=/pages/index.js

I wasn’t able to track down this bug but I don’t think it’s React fault since it works properly on CRA.

Hope it helps

I tried this same strategy on a Vue project. It works beautifully. Much appreciated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cursor jumps to the start of input when changing input type
Input some text. Click password visibility icon button. Cursor jumps to the start of input.
Read more >
Why does cursor move to start of input field when value is ...
First, i do not understand why my input field is setting cursor to start of the input field even though i am changing...
Read more >
Possible fix of cursor jumping at the end of the input field
A possible fix is to save and restore the position of the cursor (aka caret) while updating the input field with something like...
Read more >
Updating input fields without losing the cursor position
When the input field updates as you're typing, the cursor jumps to the end of the input. This is a side-effect of not...
Read more >
The Curious Case of Cursor Jumping - Mutually Human
Programmatically changing the text field value resets its cursor position · Single line text fields (via <input type=text /> resets the cursor to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found