yury-dymov / react-autocomplete-input

Autocomplete input field for React
https://yury-dymov.github.io/react-autocomplete-input/
MIT License
199 stars 65 forks source link

Cyrillic words are not working in autocomplete with empty trigger #56

Closed amb-it closed 3 years ago

amb-it commented 3 years ago

if I set array of suggestions from Cyrillic words, they are not shown in autocomplete, while Latin autosuggestion works fine. For example <TextInput options={['one','two','три','четыре','five']} trigger='' /> only if I type in input Latin 'o', 'on', 'fiv' and so on - suggestions will be shown. If I type Cyrillic 'т', 'тр', 'четы' - no suggestions shown.

p.s. anyway thanks for great library!

amb-it commented 3 years ago

I have digged in the source code and just found solution)) so there is regex, which by default is ^[a-zA-Z0-9_\-]+$. If to add Cyrillic letters - it will work fine: <TextInput options={['one','two','три','четыре','five']} trigger='' regex='^[a-zA-Zа-яА-Я0-9_\-]+$' />

so my suggestion is to widen default regex to have all other letters, because - why it should be restricted only by Latin ?

yury-dymov commented 3 years ago

Well, there was no need to dig in the source code as this behavior is documented in the repo readme: https://github.com/yury-dymov/react-autocomplete-input :)

Latin is a good default, which will work for the majority of people. On top of that vanilla js regex is not very localization friendly out-of-the-box, so changing a-z to something like \w won't work as we would expect. This is a good example, how more or less universal regex will look like: https://github.com/yury-dymov/js-regex-pl/blob/master/src/index.js. So I don't think there is a good universal solution that would fit all needs. By widening default regex with a truly universal set we will bloat the library size several times, which would be unnecessary for most folks, who might consider using this package.

Being said, I am happy with the current trade-off: default regex is good enough in the vast majority of cases and there is an easy way available to override it for the rest. Hence, closing this.