LouisMazel / maz-ui

Vue & Nuxt library of standalone components & tools to build interfaces

Home Page:https://maz-ui.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG][MazPhoneNumberInput] Jump cursor; as you type

pboos opened this issue · comments

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://louismazel.github.io/maz-ui/documentation/maz-phone-number-input/
  2. Scroll down to Examples
  3. Click inside a phone number and enter 1234
  4. Move the curser in front of 1 and type 5678 to change the input to 56781234
  5. -> Because the cursor jumps to the end it will have the value 51234678 and not what I wanted

Expected behavior
Cursor should stay where it is and the input should now be 56781234

Desktop:

  • OS: MacOS
  • Browser: Chrome
  • Version: 89.0.4389.82

Is there a fix for this yet?

I would really prioritise this issue. I am currently trying to analyse this library and specifically this special Mobile Phone Number Input component.
This Issue quite a show blocker in our Projects.

I blame the set in the main.vue of MazInput here:

computed: {
inputValue: {
get () {
return this.value
},
set (value) {
const valueToEmit = this.hasNumberType
? !value ? 0 : parseInt(value)
: value
this.emitValue(valueToEmit)
}
},

My guess is that either parseInt or the setter itself "renters" the value in the input, thus pushing the cursor to the end.
My recommendation for input validation is to either supporting masks or just show some kind of error message below the input field.
Or evaluate the input on focusLoose.