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

Fix single option autocompletion #78

Closed nikhil-varma closed 2 years ago

nikhil-varma commented 2 years ago

If there are any options with a single character, the autocomplete input field ignores that and does not show anything in the dropdown as choices.

This PR fixes this by ensuring that options with at least one character is used.

Eg: [z] is the only option that is available. If you type z in the input, it does not show up in the autocomplete dropdown

Codesandbox link - with error and with fix

https://codesandbox.io/s/dazzling-morse-ybiwd7

nikhil-varma commented 2 years ago

@yury-dymov Can you please review this?

nikhil-varma commented 2 years ago

@yury-dymov Please let me know if this is possible to release soon 🙂 Thanks!

yury-dymov commented 2 years ago

Hi, thank you for the contribution. As you might have seen, I don't actively support things unfortunately :/

Even though I understand the edge case you are trying to fix, I don't agree with the solution as it breaks existing behavior for regular case having only one word available with the length > 1, and therefore I am not going to merge it.

However, I am okay with following:

 if (
        slug.matchLength >= minChars
        && (
          slug.options.length > 1
          || (
            slug.options.length === 1
            && (slug.options[0].length !== slug.matchLength || slug.options[0].length === 1)
...

This is something I can land if it helps.

nikhil-varma commented 2 years ago

@yury-dymov Thank you so much for getting back and reviewing this. Really appreciate your thought for this.

I have incorporated the suggested change and have tested it. Does this look okay?

I have updated the codesandbox link as well. Please let me know if we can merge this. 🙂

Thank you again!