Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] Support for searching countries by filtering as you type, and/or by abbreviations #1922

Open
keisha-rw opened this issue Jan 7, 2025 · 2 comments

Comments

@keisha-rw
Copy link

Currently, the library supports searching for countries within the dropdown; however, the search functionality does not allow users to filter countries in a couple key ways:

  • Filtering as you type - matching countries whose names start with the entered search term (e.g., typing "U" should immediately filter to "United States," "United Kingdom," etc.). This could perhaps be achieved by adding an additional option to configure the search behavior (e.g., searchMode: "startswith" | "includes").
  • Country abbreviations - matching countries by their abbreviations or common short forms (e.g., typing "US" for "United States" or "UK" for "United Kingdom"). Perhaps you could use ISO 3166-1 alpha-2/alpha-3 codes in the search index.

What are your thoughts on enhancing the country search functionality in the aforementioned ways?

Thank you for your work on this project! It truly is appreciated. 🌟

@jackocnr
Copy link
Owner

jackocnr commented Jan 9, 2025

Hi there, thanks for the suggestions. So to clarify, we do currently filter on what is typed, but we don't do any re-ordering - it's just any countries that contain that string will appear in the list, in chronological order. Based on your suggestions, I think it would be a nice improvement to add some simple weighting, so if a country starts with the query string, then it should be weighted higher than a country that includes the string in another position. Likewise, we could prioritise abbreviations (probably only after 2 characters have been typed), probably weighting them even higher than countries starting with the query string.

So the weighting hierarchy would be:

  • Abbreviation matches (when 2+ chars typed)
  • Starts with
  • Includes

What do you think?

At some point, we may think of more weighting levels we want to implement (e.g. maybe country population?), but I think this would be a good start.

I don't have time to implement this myself right now, but would welcome a pull request.

@keisha-rw
Copy link
Author

Thanks for your response, @jackocnr! I apologize for my mistake with how things are currently filtered. 🙈

I do like the idea of focusing on abbreviations first, then using starts with, and then includes. This would meet our needs and improve the user experience. Additional weighting levels like country population would be an interesting feature to play around with at some point, but it might not be worth the additional js bloat it would create. It'd be something worth investigating at some point down the road, though!

I have someone from my team looking into implementing your weighting hierarchy suggestion; we'll hopefully be able to get a PR out to you soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants