@descope/web-components-ui 3.13.1 → 3.13.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -135,6 +135,14 @@ class PhoneFieldInternal extends BaseInputClass {
135
135
  }
136
136
 
137
137
  set value(val) {
138
+ this.#onValueChange(val);
139
+ }
140
+
141
+ // Handles programmatic value changes only (e.g. `component.value = '...'`).
142
+ // User edits of the inner inputs are handled by #onTextFieldChange /
143
+ // #onComboBoxChange — Vaadin's value write-back is disabled in PhoneFieldClass
144
+ // so it no longer routes inner edits through this setter.
145
+ #onValueChange(val) {
138
146
  // reject empty or digit-free values
139
147
  if (!val || !/\d/.test(val)) {
140
148
  this.#clearValue();
@@ -267,22 +275,37 @@ class PhoneFieldInternal extends BaseInputClass {
267
275
  }
268
276
 
269
277
  #initInputs() {
270
- // Sanitize phone input value to filter everything but digits
271
- this.textField.addEventListener('input', (e) => {
272
- if (!this.allowAlphanumericInput) {
273
- const telDigitsRegExp = /^\d$/;
274
- const sanitizedInput = e.target.value
275
- .split('')
276
- .filter((char) => telDigitsRegExp.test(char))
277
- .join('');
278
- e.target.value = sanitizedInput;
279
- }
280
- });
278
+ // Handle each inner input on its own: the phone field updates the national
279
+ // number, the combo box updates the country/dial code. Neither rewrites the
280
+ // other, so editing one input never clears the other.
281
+ this.textField.addEventListener('input', this.#onTextFieldChange.bind(this));
282
+ this.comboBox.addEventListener('change', this.#onComboBoxChange.bind(this));
281
283
 
282
284
  this.handleFocusEventsDispatching(this.inputs);
283
285
  this.handleInputEventDispatching();
284
286
  }
285
287
 
288
+ // user edited the phone number: sanitize and (optionally) format it, leaving
289
+ // the country code untouched
290
+ #onTextFieldChange() {
291
+ const sanitized = this.allowAlphanumericInput
292
+ ? this.textField.value
293
+ : this.textField.value.replace(/\D+/g, '');
294
+
295
+ this.textField.value = this.isFormatValue ? this.#formatNationalNumber(sanitized) : sanitized;
296
+ }
297
+
298
+ // user changed the country: re-format the existing national number for the
299
+ // new country, leaving the phone number digits untouched
300
+ #onComboBoxChange() {
301
+ if (!this.isFormatValue) {
302
+ return;
303
+ }
304
+
305
+ const nationalNumber = this.textField.value.replace(/\D+/g, '');
306
+ this.textField.value = this.#formatNationalNumber(nationalNumber);
307
+ }
308
+
286
309
  #formatNationalNumber(nationalNumber = '') {
287
310
  // re-initialize AsYouType if country code is outdated
288
311
  if (!this.#ayt || this.#ayt.country !== this.selectedCountryCode) {