Skip to content

Commit

Permalink
chore: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
waterplea committed Dec 26, 2024
1 parent ef67736 commit ae73c30
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const NOT_FORM_CONTROL_SYMBOLS = /[^+\d]/g;
'[disabled]': 'disabled()',
'[value]': 'masked()',
'(blur)': 'onTouched()',
'(input)': 'onInput()',
'(input)': 'onChange(unmasked)',
'(click)': 'open.set(false)',
'(beforeinput.capture)': 'onPaste($event)',
},
Expand Down Expand Up @@ -184,12 +184,10 @@ export class TuiInputPhoneInternational extends TuiControl<string> {
this.dropdown.set(template);
}

protected onInput(): void {
protected get unmasked(): string {
const value = this.el.value.replaceAll(NOT_FORM_CONTROL_SYMBOLS, '');

this.onChange(
value === tuiGetCallingCode(this.code(), this.metadata()) ? '' : value,
);
return value === tuiGetCallingCode(this.code(), this.metadata()) ? '' : value;
}

protected onPaste(event: Event): void {
Expand All @@ -212,12 +210,17 @@ export class TuiInputPhoneInternational extends TuiControl<string> {
}
}

protected onItemClick(isoCode: TuiCountryIsoCode): void {
protected onItemClick(code: TuiCountryIsoCode): void {
this.el.focus();
this.el.value = this.el.value || tuiGetCallingCode(this.code(), this.metadata());
this.el.value = this.unmasked;
this.open.set(false);
this.code.set(isoCode);
this.code.set(code);
this.search.set('');
this.el.value = maskitoTransform(
this.el.value || tuiGetCallingCode(code, this.metadata()),
this.mask() || MASKITO_DEFAULT_OPTIONS,
);
this.onChange(this.unmasked);
}

private computeMask(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type {DebugElement} from '@angular/core';
import {ChangeDetectionStrategy, Component, ViewChild} from '@angular/core';
import type {ComponentFixture} from '@angular/core/testing';
import {TestBed} from '@angular/core/testing';
Expand Down Expand Up @@ -189,7 +188,7 @@ describe('InputPhoneInternational', () => {
initializeTestModule(TUI_RUSSIAN_LANGUAGE);

it('displays country names in Russian inside dropdown', () => {
getCountrySelector().nativeElement.click();
clickCountrySelector();
fixture.detectChanges();

expect(getDropdownCountryNames()).toEqual([
Expand All @@ -207,7 +206,7 @@ describe('InputPhoneInternational', () => {
initializeTestModule(TUI_ENGLISH_LANGUAGE);

it('displays country names in English inside dropdown', () => {
getCountrySelector().nativeElement.click();
clickCountrySelector();
fixture.detectChanges();

expect(getDropdownCountryNames()).toEqual([
Expand Down Expand Up @@ -245,7 +244,9 @@ describe('InputPhoneInternational', () => {
);
}

function getCountrySelector(): DebugElement {
return fixture.debugElement.query(By.css('.t-ipi-select'));
function clickCountrySelector(): void {
return fixture.debugElement
.query(By.css('.t-ipi-select'))
.nativeElement.dispatchEvent(new Event('mousedown'));
}
});

0 comments on commit ae73c30

Please sign in to comment.