@descope/web-components-ui 3.1.10 → 3.1.12

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
@@ -11201,12 +11201,21 @@ let PhoneFieldInternal$1 = class PhoneFieldInternal extends BaseInputClass$a {
11201
11201
  return;
11202
11202
  }
11203
11203
 
11204
- // resolve country code from dial code
11205
- const countryCode = CountryCodes.find((c) => c.dialCode === dialCode)?.code;
11204
+ // Collect all country codes sharing this dial code from CountryCodes (e.g. US, CA, DO, ... for +1)
11205
+ const matchingCountryCodes = CountryCodes.filter((c) => c.dialCode === dialCode).map(
11206
+ (c) => c.code
11207
+ );
11206
11208
 
11207
- // sync combo box when country changes
11208
- if (countryCode && countryCode !== this.selectedCountryCode) {
11209
- this.comboBox.selectedItem = this.#getCountryItemByCodeId(countryCode);
11209
+ // Check if the currently selected country's data-country-code is in that set
11210
+ const currentSelectedCountryCode = this.selectedCountryCode;
11211
+ if (!matchingCountryCodes.includes(currentSelectedCountryCode)) {
11212
+ // If not, find the first combo box item (restricted list) whose data-country-code is in the set
11213
+ const matchingItem = this.comboBox.items?.find((c) =>
11214
+ matchingCountryCodes.includes(c.getAttribute('data-country-code'))
11215
+ );
11216
+ if (matchingItem) {
11217
+ this.comboBox.selectedItem = matchingItem;
11218
+ }
11210
11219
  }
11211
11220
 
11212
11221
  // set formatted or raw national number on the text field
@@ -19155,13 +19164,21 @@ class RawHybridField extends BaseClass$6 {
19155
19164
  });
19156
19165
  }
19157
19166
 
19167
+ #getDefaultDialCode() {
19168
+ const code = this.getAttribute('default-code');
19169
+ const match = code && PhoneFieldClass.CountryCodes.find((c) => c.code === code);
19170
+ return match?.dialCode || PhoneFieldClass.CountryCodes[0]?.dialCode || '';
19171
+ }
19172
+
19158
19173
  setActiveInputValue(val) {
19159
19174
  const sanitizedVal = sanitizeCountryCodePrefix(val);
19160
19175
  const isPhoneField = this.activeInput.localName === PHONE_FIELD;
19161
- const value = isPhoneField
19162
- ? `${this.phoneCountryCodeInput.countryCodeItems}-${sanitizedVal}`
19163
- : sanitizedVal;
19164
- this.activeInput.value = value;
19176
+ if (isPhoneField) {
19177
+ const dialCode = this.phoneCountryCodeInput.countryCodeItems || this.#getDefaultDialCode();
19178
+ this.activeInput.value = `${dialCode}-${sanitizedVal}`;
19179
+ } else {
19180
+ this.activeInput.value = sanitizedVal;
19181
+ }
19165
19182
  }
19166
19183
 
19167
19184
  toggleInputVisibility() {