@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.
- package/dist/cjs/index.cjs.js +92 -3
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.esm.js +126 -14
- package/dist/index.esm.js.map +1 -1
- package/dist/umd/DescopeDev.js +1 -1
- package/dist/umd/DescopeDev.js.map +1 -1
- package/dist/umd/descope-anchored.js +1 -1
- package/dist/umd/descope-anchored.js.map +1 -1
- package/dist/umd/descope-attachment.js +1 -1
- package/dist/umd/descope-attachment.js.map +1 -1
- package/dist/umd/descope-tooltip.js +1 -1
- package/dist/umd/descope-tooltip.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/phone-fields-descope-phone-field-descope-phone-field-internal-index-js.js +1 -1
- package/dist/umd/phone-fields-descope-phone-field-descope-phone-field-internal-index-js.js.map +1 -1
- package/dist/umd/phone-fields-descope-phone-field-index-js.js +1 -1
- package/dist/umd/phone-fields-descope-phone-field-index-js.js.map +1 -1
- package/package.json +39 -39
- package/src/components/phone-fields/descope-phone-field/PhoneFieldClass.js +6 -0
- package/src/components/phone-fields/descope-phone-field/descope-phone-field-internal/PhoneFieldInternal.js +34 -11
|
@@ -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
|
-
//
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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) {
|