Skip to content

Commit

Permalink
fix(kit): correct detect iso code for Kazakhstan when phone number …
Browse files Browse the repository at this point in the history
…start with `+7` (#4217)
  • Loading branch information
splincode authored Apr 14, 2023
1 parent 2c40931 commit 0080ac8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {TuiCountryIsoCode} from '@taiga-ui/i18n';
})
export class TuiInputPhoneExample1 {
readonly testForm = new FormGroup({
testValue: new FormControl('+77777777777', Validators.required),
testValue: new FormControl('+79777777777', Validators.required),
});

readonly countries: readonly TuiCountryIsoCode[] = [
Expand Down
1 change: 1 addition & 0 deletions projects/kit/components/input-phone-international/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './input-phone-international.module';
export * from './input-phone-international.options';
export * from './tokens/countries-masks';
export * from './utils/extract-value-from-event';
export * from './utils/not-kz-region';
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
} from './input-phone-international.options';
import {TUI_COUNTRIES_MASKS} from './tokens/countries-masks';
import {tuiExtractValueFromEvent} from './utils/extract-value-from-event';
import {tuiNotKzRegion} from './utils/not-kz-region';

@Component({
selector: 'tui-input-phone-international',
Expand Down Expand Up @@ -246,13 +247,16 @@ export class TuiInputPhoneInternationalComponent
/^(?!880[1-9 ])/.test(value) &&
value.length + 1 === this.getMaxAllowedLength(TuiCountryIsoCode.RU);

return (
const matched =
ruCodeTest ||
(value.startsWith(
this.isoToCountryCode(countryIsoCode).replace(CHAR_PLUS, ''),
) &&
value.length + 1 === this.getMaxAllowedLength(countryIsoCode))
);
value.length + 1 === this.getMaxAllowedLength(countryIsoCode));

return matched && countryIsoCode === TuiCountryIsoCode.RU
? tuiNotKzRegion(value)
: matched;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ describe(`InputPhoneInternational`, () => {
expect(component.countryIsoCode).toBe(TuiCountryIsoCode.RU);
});

describe(`should set KZ country code on paste event`, () => {
for (const phone of [`+7(600)555-3535`, `+7 7272 588300`]) {
it(phone, () => {
const data = new DataTransfer();

data.setData(`text/plain`, phone);

const pasteEvent = new ClipboardEvent(`paste`, {
clipboardData: data as unknown as DataTransfer,
});

component.onPaste(pasteEvent);

expect(component.countryIsoCode).toBe(TuiCountryIsoCode.KZ);
});
}
});

it(`should replace code 8 on paste event`, () => {
const data = new DataTransfer();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function tuiNotKzRegion(value: string): boolean {
const region = Number(value.slice(1, 4));

return region < 600 || region > 799;
}

0 comments on commit 0080ac8

Please sign in to comment.