@descope/web-components-ui 3.13.2 → 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/index.esm.js CHANGED
@@ -11463,6 +11463,14 @@ let PhoneFieldInternal$1 = class PhoneFieldInternal extends BaseInputClass$c {
11463
11463
  }
11464
11464
 
11465
11465
  set value(val) {
11466
+ this.#onValueChange(val);
11467
+ }
11468
+
11469
+ // Handles programmatic value changes only (e.g. `component.value = '...'`).
11470
+ // User edits of the inner inputs are handled by #onTextFieldChange /
11471
+ // #onComboBoxChange — Vaadin's value write-back is disabled in PhoneFieldClass
11472
+ // so it no longer routes inner edits through this setter.
11473
+ #onValueChange(val) {
11466
11474
  // reject empty or digit-free values
11467
11475
  if (!val || !/\d/.test(val)) {
11468
11476
  this.#clearValue();
@@ -11595,22 +11603,37 @@ let PhoneFieldInternal$1 = class PhoneFieldInternal extends BaseInputClass$c {
11595
11603
  }
11596
11604
 
11597
11605
  #initInputs() {
11598
- // Sanitize phone input value to filter everything but digits
11599
- this.textField.addEventListener('input', (e) => {
11600
- if (!this.allowAlphanumericInput) {
11601
- const telDigitsRegExp = /^\d$/;
11602
- const sanitizedInput = e.target.value
11603
- .split('')
11604
- .filter((char) => telDigitsRegExp.test(char))
11605
- .join('');
11606
- e.target.value = sanitizedInput;
11607
- }
11608
- });
11606
+ // Handle each inner input on its own: the phone field updates the national
11607
+ // number, the combo box updates the country/dial code. Neither rewrites the
11608
+ // other, so editing one input never clears the other.
11609
+ this.textField.addEventListener('input', this.#onTextFieldChange.bind(this));
11610
+ this.comboBox.addEventListener('change', this.#onComboBoxChange.bind(this));
11609
11611
 
11610
11612
  this.handleFocusEventsDispatching(this.inputs);
11611
11613
  this.handleInputEventDispatching();
11612
11614
  }
11613
11615
 
11616
+ // user edited the phone number: sanitize and (optionally) format it, leaving
11617
+ // the country code untouched
11618
+ #onTextFieldChange() {
11619
+ const sanitized = this.allowAlphanumericInput
11620
+ ? this.textField.value
11621
+ : this.textField.value.replace(/\D+/g, '');
11622
+
11623
+ this.textField.value = this.isFormatValue ? this.#formatNationalNumber(sanitized) : sanitized;
11624
+ }
11625
+
11626
+ // user changed the country: re-format the existing national number for the
11627
+ // new country, leaving the phone number digits untouched
11628
+ #onComboBoxChange() {
11629
+ if (!this.isFormatValue) {
11630
+ return;
11631
+ }
11632
+
11633
+ const nationalNumber = this.textField.value.replace(/\D+/g, '');
11634
+ this.textField.value = this.#formatNationalNumber(nationalNumber);
11635
+ }
11636
+
11614
11637
  #formatNationalNumber(nationalNumber = '') {
11615
11638
  // re-initialize AsYouType if country code is outdated
11616
11639
  if (!this.#ayt || this.#ayt.country !== this.selectedCountryCode) {
@@ -11737,6 +11760,12 @@ const customMixin$b = (superclass) =>
11737
11760
 
11738
11761
  this.baseElement.appendChild(template.content.cloneNode(true));
11739
11762
 
11763
+ // On every input, Vaadin writes its value back into the input element,
11764
+ // which re-runs the internal `value` setter and overwrites the combo box
11765
+ // and phone fields. PhoneFieldInternal manages those inputs itself, so
11766
+ // disable Vaadin's write-back.
11767
+ this.baseElement._forwardInputValue = () => {};
11768
+
11740
11769
  this.inputElement = this.shadowRoot.querySelector(componentName$14);
11741
11770
 
11742
11771
  forwardAttrs(this.shadowRoot.host, this.inputElement, {