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 - Option for simplified countries list #53

Open
arzatskis opened this issue Sep 17, 2024 · 4 comments
Open

💡 Feature Request - Option for simplified countries list #53

arzatskis opened this issue Sep 17, 2024 · 4 comments
Labels
question Further information is requested

Comments

@arzatskis
Copy link

arzatskis commented Sep 17, 2024

Implementation PR

No response

Reference Issues

No response

Summary

At the moment countriesList includes multiple options with different area codes for same country (e.g. Canada has options with patterns +1 (204) ..., +1 (226) ..., +1 (236) ... etc.) I believe it would be great to have an option for "basic" countries list, where there's one option per country (for Canada this would be single option with only country code in pattern+1 (...) ... ....)

I'd say for end users such list would be less overwhelming and easier to browse / find option with typing in focused <select />

Basic Example

At the moment you can do filtering / mapping on your own, something like, but it's quite cumbersome

const map = new Map<string, string[]>();

countriesList.forEach(([code, name, dial, pattern]) =>
  map.set(code, [
    code,
    name,
    dial,
    pattern.replace(
      /\((\d+)\)/,
      (_, digits) => `(${'.'.repeat(digits.length)})`
    )
  ])
);

const list = Array.from(map.values());

// additional, you'll need to extract country code from `pattern`,
// when rendering <select /> options in case you want to display it,
// as `dial` contains country code with area code

Drawbacks

The only drawback I can think of is overhead for maintainers generating / maintaining two separate .json lists

Unresolved questions

No response

@arzatskis arzatskis added the question Further information is requested label Sep 17, 2024
@ArtyomVancyan
Copy link
Member

Hi @arzatskis, thanks for sharing your thoughts. The thing is that the +1 (...) ... ....) phone mask is not only for Canada but +1 (204) ..., +1 (226) ..., +1 (236) ... etc. are.

  • +1 (340) – United States Virgin Islands.
  • +1 (670) – Northern Mariana Islands.
  • +1 (671) – Guam.
  • +1 (684) – American Samoa.
  • +1 (787, 939) – Puerto Rico.

This allows us to identify the country and so perform corresponding restrictions and validations based on that.

@arzatskis
Copy link
Author

Yeah, I understand that, but it may still return first match from list and refine matched country as user types in more digits?

@ArtyomVancyan
Copy link
Member

Yeah, I understand that, but it may still return first match from list and refine matched country as user types in more digits?

Sorry @arzatskis, but I don't see any issues with this. With the current implementation, it reidentifies the country's metadata, while with the suggested feature, it will always be the first matched country. For example, if the phone number starts with +1, it will identify the first country satisfying the +1 mask, and if the area code doesn't belong to the country it matched first, it will cause validation issues for that user.

@arzatskis
Copy link
Author

When typing everything seems to work ok. What i had in mind, that lots of options in the dropdown are not very easy to browse and I'd say quite overwhelming.

image

Did some mapping of original countriesList, things seem to work fine. Just thought maybe this come out of the box / or as an option

Some work in progress :)

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants