LouisMazel / maz-ui

Vue & Nuxt library of standalone components & tools to build interfaces
https://maz-ui.com
MIT License
476 stars 66 forks source link

[Issue with Phone number component][<Maz ui Phone number>] #1176

Open hadelnasr opened 4 weeks ago

hadelnasr commented 4 weeks ago

Describe the bug

Reference to the old hotfix for auto formatting issue here https://github.com/LouisMazel/maz-ui/issues/1139

it produces another issue when setting the :auto-format="false" option, in the edit mode it's not displaying the phone number

To Reproduce

Steps to reproduce the behavior:

add this logic in your vuejs code <MazPhoneNumberInput v-model="localPhoneNumber" :auto-format="false" /> const localPhoneNumber = props.phoneNumber;

where the props.phoneNumber equals: +201000000000 (egypt mobile number)

Expected behavior

Should render this way image

Actual behavior

shown this way image

LouisMazel commented 4 weeks ago

This code is not correct

const localPhoneNumber = props.phoneNumber

localPhoneNumber is not reactive and can't be modify.

Use it instead

const localPhoneNumber = ref(props.phoneNumber)
hadelnasr commented 2 weeks ago

Dear @LouisMazel

i tried adding your code and it's the same bug behavior const localPhoneNumber = ref(props.phoneNumber)

hadelnasr commented 2 weeks ago

@LouisMazel any recommendations?

LouisMazel commented 2 weeks ago

Can you provide a reproduction link with stackblitz or any other ?

I can't help you like this. All is fine with others users

LouisMazel commented 2 weeks ago

Working example: https://stackblitz.com/edit/maz-ui-vue3-phonenumber?file=src/App.vue

hadelnasr commented 2 weeks ago

Working example: https://stackblitz.com/edit/maz-ui-vue3-phonenumber?file=src/App.vue

will you provide a quick example with a default phone number not empty string?

try the below one const phoneNumber = ref<string>('01224647411') const countryCode = ref<CountryCode>('EG')

the phone number will not preloaded

LouisMazel commented 2 weeks ago

Hi,

I released a beta version with the fix, can you try it and tell me if it's good?

The beta version is: 3.47.2-beta.14

Install it:

npm install maz-ui@3.47.2-beta.14

Thanks for your feedback :)

hadelnasr commented 2 weeks ago

@LouisMazel ok will give it a try and get back to you soon thanks

Ziad-Ashraf-0 commented 2 weeks ago

@LouisMazel using the following reproduction link the described bug seems to be fixed https://stackblitz.com/edit/maz-ui-vue3-phonenumber-kmzvzz?file=src%2FApp.vue

However, I came across another bug related to this fix I think

LouisMazel commented 2 weeks ago

@Ziad-Ashraf-0

Thank you a lot for the details.

A new beta version is available if you want test it : 3.47.2-beta.18

Ziad-Ashraf-0 commented 1 week ago

@LouisMazel

Thank you for the quick response—it's resolved now!

However, I noticed some weird behavior with countries with a dialing code of +1. Some work fine, but others do not. For example, try a country like Bermuda, and input the example number 370-1234. When you delete it, the "4" and "3" will get deleted as expected, but when you press backspace at "2," a strange behavior occurs—it duplicates the dialing code. Also, if I try to input the example phone with the dialing code ( input 4413701 ), it duplicates the dialing code after I type the last "1".

I think it might be an issue with the parsePhoneNumberFromString function from libphonenumber-js.

Here is a link to reproduction indicating more examples https://stackblitz.com/edit/maz-ui-vue3-phonenumber-kmzvzz?file=src%2FApp.vue

hadelnasr commented 1 week ago

@LouisMazel thanks to provide us with your quick response as usual regarding the reported issue from @Ziad-Ashraf-0

LouisMazel commented 2 days ago

After much investigation and time spent, to fix all the issues the only solution I found is to only display the formatted number ("as you type") at the time of blur. When the input is focused, the number entered by the user is displayed.

So that you can see what it looks like, it is almost the same UX as the MazInputPrice component.

This allows me only to use the value entered by the user to validate the phone number, not the formatted value, and therefore avoid errors that can happen with libphonenumber-js during formatting or validation and avoid unwanted behaviors.

I release it in the beta v3.47.2-beta.22 And you can test it here : https://stackblitz.com/edit/maz-ui-vue3-phonenumber?file=src/App.vue