react-native-mask-input icon indicating copy to clipboard operation
react-native-mask-input copied to clipboard

Editing input field causes cursor to jump to end of string

Open dsound-zz opened this issue 2 years ago • 14 comments

When I try to edit within the date field, the cursor moves to the end of the string and instead of being able to backspace and insert a new value.

Steps to reproduce:


import { formatWithMask } from 'react-native-mask-input'


const Test = () => {
  const [date, setDate] = useState('')

  const { masked } = formatWithMask({
    text: date,
    mask: [/\d/, /\d/, '/', /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/],
  })

 return (
   <>
     <input placeholder="mm/dd/yyyy" value={masked} onChange={(val) => setDate(val)} name="date" />
   </>
  )

}

export default Test

Expected behavior: Be able to click within date, backspace to remove value and add new value

Actual behavior: The second slash is removed and the cursor is moved to the back of the input

dsound-zz avatar May 18 '22 14:05 dsound-zz

👆 ++

oliviercperrier avatar Jan 11 '23 14:01 oliviercperrier

++

Buzzzatti avatar Jan 14 '23 22:01 Buzzzatti

up

oliviercperrier avatar Feb 16 '23 18:02 oliviercperrier

This issue is causing us to reconsider using the library, unfortunately. It degrades the UX and confuses users.

bombillazo avatar Feb 28 '23 19:02 bombillazo

There's no reproducible code

CaioQuirinoMedeiros avatar Feb 28 '23 20:02 CaioQuirinoMedeiros

are you guys just using the formatWithMask function on a web project with a input html tag? so the cursor position is not function's fault.

You can try use the hook useMaskedInputProps, see the example usage on README and adapt to use within the input html

CaioQuirinoMedeiros avatar Feb 28 '23 20:02 CaioQuirinoMedeiros

Personally im using the MaskedInput from the library and its doing the same problem as mention in this issue.

I'm currently looking at an alternative library because i get bad feedback from users of my app juste because of this.

oliviercperrier avatar Mar 01 '23 12:03 oliviercperrier

@CaioQuirinoMedeiros Here is a repro link: https://codesandbox.io/s/immutable-morning-9ioot7?file=/src/App.js

Editing the year is ok, but when you try to edit the day or the month, you'll see the problem, everything get shifted to the left.

Would be great if it could work like this react library (which is not compatible with react-native unfortunately): http://sanniassin.github.io/react-input-mask/demo.html

oliviercperrier avatar Mar 01 '23 21:03 oliviercperrier

@CaioQuirinoMedeiros Any updates? Thanks

oliviercperrier avatar Mar 24 '23 13:03 oliviercperrier

No. Sorry guys, I'm not having time for this

CaioQuirinoMedeiros avatar Mar 24 '23 19:03 CaioQuirinoMedeiros

HI @oliviercperrier, have you picked an alternative library? The same problem. 😢

arhipy97 avatar Jul 11 '23 19:07 arhipy97

HI @oliviercperrier, have you picked an alternative library?

The same problem. 😢

@arhipy97 Ive built my own 😂

oliviercperrier avatar Jul 11 '23 22:07 oliviercperrier

@oliviercperrier Can you share how you done this please??

midhun-sa avatar Aug 22 '23 12:08 midhun-sa

In case it helps any of you, the root cause of the app is described here (not written by me, but the blog post links to this specific specific issue) https://giacomocerquone.com/keep-input-cursor-still/

zameschua avatar Feb 16 '24 03:02 zameschua