catamphetamine / react-phone-number-input

React component for international phone number input
http://catamphetamine.gitlab.io/react-phone-number-input/
MIT License
914 stars 193 forks source link

Sorting is not correct when using ZH-CN or ZH-TW #360

Closed erickbelfy closed 3 years ago

erickbelfy commented 3 years ago

the country selects gets unsorted when using these locales. is there any property we can pass to define sorting ourselves?

catamphetamine commented 3 years ago

The sorting is done via .localeCompare().

erickbelfy commented 3 years ago

So for Chinese it doens't work properly it sorts wrong, is there a way to provide a provide a sorting attribute where we can do our own sorting? instead of creating our own select just for two languages?

catamphetamine commented 3 years ago

Currently there's no such possibility. You can create a bug somewhere in W3C spec discussion repos or somewhere and report your case to them.

erickbelfy commented 3 years ago

Thanks for fast reply, i will close it.

catamphetamine commented 3 years ago

I mean, it would be easy to add some custom compareStrings() property to the component: https://gitlab.com/catamphetamine/react-phone-number-input/-/blob/995f7643f79306f2e2267e3bb1f429f678a45d21/source/phoneInputHelpers.js#L53 https://gitlab.com/catamphetamine/react-phone-number-input/-/blob/995f7643f79306f2e2267e3bb1f429f678a45d21/source/PhoneInputWithCountry.js#L471 https://gitlab.com/catamphetamine/react-phone-number-input/-/blob/995f7643f79306f2e2267e3bb1f429f678a45d21/source/PhoneInputWithCountry.js#L672 But if something like that was added, would it advocate people using an incorrect approach to implementing sorting? Why wouldn't .localeCompare() produce the correct results all the time? There can be different "collations" for same locales too, read MDN for what it is.

erickbelfy commented 3 years ago

for chinese traditional and simplified it doesn't , it puts libanon as a last position for instance. this means that .localeCompare is broken, i say that based on a language we can provide some particular sorting methods