Skip to content

Commit

Permalink
fix(phone-number): empty string on odsChange event
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Esteves <[email protected]>
  • Loading branch information
aesteves60 authored and dpellier committed Nov 28, 2024
1 parent f6b0f00 commit da4a77d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class OdsPhoneNumber {
private async onOdsChange(event: OdsInputChangeEvent): Promise<void> {
event.stopImmediatePropagation();

this.value = event.detail.value as string ?? null;
this.value = event.detail.value as string | null;

if (!isValidPhoneNumber(this.value, this.isoCode, this.phoneUtils)) {
await this.inputElement?.setCustomValidity(this.customValidityMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ type TranslatedCountryMap = Map<OdsPhoneNumberCountryIsoCode, { isoCode: OdsPhon
const VALUE_DEFAULT_VALUE = null;

function formatPhoneNumber(value: string | null, isoCode: OdsPhoneNumberCountryIsoCode | undefined, phoneUtils: PhoneNumberUtil): string | null {
if (value === '') {
return '';
}

const phoneNumber = parsePhoneNumber(value, isoCode, phoneUtils);

if (!phoneNumber) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('ods-phone-number behaviour', () => {
isoCode: 'fr',
previousValue: null,
validity: {},
value: null,
value: '',
});
});
});
Expand All @@ -95,7 +95,7 @@ describe('ods-phone-number behaviour', () => {
isoCode: 'fr',
previousValue: null,
validity: {},
value: null,
value: '',
});
});
});
Expand Down

0 comments on commit da4a77d

Please sign in to comment.