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

Added ScrollIntoView Options to display the position of the country search #385

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 36 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,45 +80,47 @@ Or this:

```html
<form #f="ngForm" [formGroup]="phoneForm">
<ngx-intl-tel-input
[cssClass]="'custom'"
[preferredCountries]="[CountryISO.UnitedStates, CountryISO.UnitedKingdom]"
[enableAutoCountrySelect]="false"
[enablePlaceholder]="true"
[searchCountryFlag]="true"
[searchCountryField]="[SearchCountryField.Iso2, SearchCountryField.Name]"
[selectFirstCountry]="false"
[selectedCountryISO]="CountryISO.India"
[maxLength]="15"
[phoneValidation]="true"
[inputId]="my-input-id"
name="phone"
formControlName="phone"
></ngx-intl-tel-input>
<ngx-intl-tel-input
[cssClass]="'custom'"
[preferredCountries]="preferredCountries"
[enableAutoCountrySelect]="true"
[enablePlaceholder]="true"
[searchCountryFlag]="true"
[searchCountryField]="[SearchCountryField.Iso2, SearchCountryField.Name]"
[selectFirstCountry]="false"
[selectedCountryISO]="CountryISO.India"
[maxLength]="15"
[phoneValidation]="true"
[separateDialCode]="separateDialCode"
[numberFormat]="PhoneNumberFormat.National" name="phone"
[scrollIntoViewOptions]="{ behavior: 'smooth', block: 'start', inline: 'nearest' }"
formControlName="phone">
</ngx-intl-tel-input>
</form>
```

## Options

| Options | Type | Default | Description |
| ------------------------ | ------------------------ | --------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| cssClass | `string` | `control-form` | Bootstrap input css class or your own custom one. |
| preferredCountries | `<CountryISO>[]` | `[]` | List of countries, which will appear at the top. |
| onlyCountries | `<CountryISO>[]` | `[]` | List of manually selected countries, which will appear in the dropdown. |
| enableAutoCountrySelect | `boolean` | `true` | Toggle automatic country (flag) selection based on user input. |
| enablePlaceholder | `boolean` | `true` | Input placeholder text, which adapts to the country selected. |
| customPlaceholder | `string` | `None` | Custom string to be inserted as a placeholder. |
| numberFormat | `<PhoneNumberFormat>` | `PhoneNumberFormat.International` | Custom string to be inserted as a placeholder. |
| searchCountryFlag | `boolean` | `false` | Enables input search box for countries in the flag dropdown. |
| searchCountryField | `<SearchCountryField>[]` | `[SearchCountryField.All]` | Customize which fields to search in, if `searchCountryFlag` is enabled. Use `SearchCountryField` helper enum. |
| searchCountryPlaceholder | `string` | `'Search Country'` | Placeholder value for `searchCountryField` |
| maxLength | `number` | `None` | Add character limit. |
| selectFirstCountry | `boolean` | `true` | Selects first country from `preferredCountries` if is set. If not then uses main list. |
| phoneValidation | `boolean` | `true` | Disable phone validation. |
| inputId | `string` | `phone` | Unique ID for `<input>` element. |
| selectedCountryISO | `<CountryISO>` | `None` | Set specific country on load. |
| separateDialCode | `boolean` | `false` | Visually separate dialcode into the drop down element. |
| countryChange | `<Country>` | `None` | Emits country value when the user selects a country from the dropdown. |
| Options | Type | Default | Description |
| ------------------------ | ------------------------------------------------------ | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| cssClass | `string` | `control-form` | Bootstrap input css class or your own custom one. |
| preferredCountries | `<CountryISO>[]` | `[]` | List of countries, which will appear at the top. |
| onlyCountries | `<CountryISO>[]` | `[]` | List of manually selected countries, which will appear in the dropdown. |
| enableAutoCountrySelect | `boolean` | `true` | Toggle automatic country (flag) selection based on user input. |
| enablePlaceholder | `boolean` | `true` | Input placeholder text, which adapts to the country selected. |
| customPlaceholder | `string` | `None` | Custom string to be inserted as a placeholder. |
| numberFormat | `<PhoneNumberFormat>` | `PhoneNumberFormat.International` | Custom string to be inserted as a placeholder. |
| searchCountryFlag | `boolean` | `false` | Enables input search box for countries in the flag dropdown. |
| searchCountryField | `<SearchCountryField>[]` | `[SearchCountryField.All]` | Customize which fields to search in, if `searchCountryFlag` is enabled. Use `SearchCountryField` helper enum. |
| searchCountryPlaceholder | `string` | `'Search Country'` | Placeholder value for `searchCountryField` |
| maxLength | `number` | `None` | Add character limit. |
| selectFirstCountry | `boolean` | `true` | Selects first country from `preferredCountries` if is set. If not then uses main list. |
| phoneValidation | `boolean` | `true` | Disable phone validation. |
| inputId | `string` | `phone` | Unique ID for `<input>` element. |
| selectedCountryISO | `<CountryISO>` | `None` | Set specific country on load. |
| separateDialCode | `boolean` | `false` | Visually separate dialcode into the drop down element. |
| countryChange | `<Country>` | `None` | Emits country value when the user selects a country from the dropdown. |
| scrollIntoViewOptions | `{ behavior: string, block: string, inline: string }` | `{ behavior: 'smooth', block: 'nearest', inline: 'nearest' }` | Options to display countries in different positions of the dropdown using the scorllIntoView options: behavior: Defines the transition animation => 'auto'-'smooth', block: Defines vertical alignment => 'start' - 'center' - 'end' - 'nearest', inline: Defines horizontal alignment => 'start' - 'center' - 'end' - 'nearest' |

## Supported Formats

Expand Down
4 changes: 2 additions & 2 deletions projects/ngx-intl-tel-input/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-intl-tel-input",
"version": "3.1.1",
"version": "3.1.2",
"peerDependencies": {
"@angular/common": "8.x - 11.x",
"@angular/core": "8.x - 11.x",
Expand Down Expand Up @@ -37,4 +37,4 @@
"devDependencies": {
"@types/google-libphonenumber": "^7.4.17"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ export class NgxIntlTelInputComponent implements OnInit, OnChanges {
@Input() phoneValidation = true;
@Input() inputId = 'phone';
@Input() separateDialCode = false;
@Input() scrollIntoViewOptions: {
behavior: string,
block: string,
inline: string,
};

separateDialCodeClass: string;

@Output() readonly countryChange = new EventEmitter<Country>();
Expand All @@ -88,8 +94,8 @@ export class NgxIntlTelInputComponent implements OnInit, OnChanges {

@ViewChild('countryList') countryList: ElementRef;

onTouched = () => {};
propagateChange = (_: ChangeData) => {};
onTouched = () => { };
propagateChange = (_: ChangeData) => { };

constructor(private countryCodeData: CountryCode) {
// If this is not set, ngx-bootstrap will try to use the bs3 CSS (which is not what we've embedded) and will
Expand Down Expand Up @@ -139,6 +145,7 @@ export class NgxIntlTelInputComponent implements OnInit, OnChanges {
}
this.updateSelectedCountry();
this.checkSeparateDialCodeStyle();
if (!this.scrollIntoViewOptions) this.scrollIntoViewOptions = { behavior: 'smooth', block: 'nearest', inline: 'nearest' };
}

setSelectedCountry(country: Country) {
Expand All @@ -154,9 +161,9 @@ export class NgxIntlTelInputComponent implements OnInit, OnChanges {
this.countryList.nativeElement
.querySelector('.iti__country-list li')
.scrollIntoView({
behavior: 'smooth',
block: 'nearest',
inline: 'nearest',
behavior: this.scrollIntoViewOptions.behavior,
block: this.scrollIntoViewOptions.block,
inline: this.scrollIntoViewOptions.inline,
});
return;
}
Expand Down Expand Up @@ -199,9 +206,9 @@ export class NgxIntlTelInputComponent implements OnInit, OnChanges {
);
if (el) {
el.scrollIntoView({
behavior: 'smooth',
block: 'nearest',
inline: 'nearest',
behavior: this.scrollIntoViewOptions.behavior,
block: this.scrollIntoViewOptions.block,
inline: this.scrollIntoViewOptions.inline,
});
}
}
Expand Down Expand Up @@ -384,7 +391,7 @@ export class NgxIntlTelInputComponent implements OnInit, OnChanges {
let number: lpn.PhoneNumber;
try {
number = this.phoneUtil.parse(phoneNumber, countryCode.toUpperCase());
} catch (e) {}
} catch (e) { }
return number;
}

Expand Down