@wix/form-public 0.573.0 → 0.575.0

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.js CHANGED
@@ -36473,6 +36473,7 @@ var require_messages_en2 = __commonJS({
36473
36473
  "input.error.message.incomplete-date-error.month-day-time": "Enter a month, day and time.",
36474
36474
  "file-upload.aria-roledescription": "File upload",
36475
36475
  "settings.appointment.duration.minutes-label": "Minutes",
36476
+ "field.phone.country-detected.announcement": "Phone country is now {countryName}.",
36476
36477
  "contacts-phone.input.error.message.pattern-error": "Enter a valid phone number.",
36477
36478
  "mla-street-number.input.error.message.required-error": "Enter a house number.",
36478
36479
  "date-picker.a11y.dropdown-month": "Select month",
@@ -59496,6 +59497,14 @@ var OpenOnPredictions = ({ optionCount }) => {
59496
59497
  ]);
59497
59498
  return null;
59498
59499
  };
59500
+ var useKeepArrowDownInOpenComboBox = () => {
59501
+ const state = useContext(ComboBoxStateContext);
59502
+ return (event) => {
59503
+ if (event.key === "ArrowDown" && state?.isOpen) {
59504
+ event.stopPropagation();
59505
+ }
59506
+ };
59507
+ };
59499
59508
 
59500
59509
  // ../form-fields/dist/esm/ui/multiline-address-field/headless/address-line-field-headless.js
59501
59510
  var AddressLine = ({ children }) => {
@@ -59638,6 +59647,7 @@ var Input4 = ({ className, ...internal }) => {
59638
59647
  const { inputId, ariaDescribedBy } = useFieldAttributes();
59639
59648
  const { onFocus } = internal;
59640
59649
  const inputRef = useRef(null);
59650
+ const keepArrowDownInOpenComboBox = useKeepArrowDownInOpenComboBox();
59641
59651
  useFocusFieldEvent(() => {
59642
59652
  inputRef.current?.focus({
59643
59653
  preventScroll: true
@@ -59646,6 +59656,7 @@ var Input4 = ({ className, ...internal }) => {
59646
59656
  useKeepPrehydrationValue(inputRef);
59647
59657
  return /* @__PURE__ */ React177.createElement(Input, {
59648
59658
  ref: inputRef,
59659
+ onKeyUpCapture: keepArrowDownInOpenComboBox,
59649
59660
  id: inputId,
59650
59661
  autoComplete: "address-line1",
59651
59662
  "aria-describedby": ariaDescribedBy,
@@ -59976,6 +59987,7 @@ var Input7 = ({ className, ...internal }) => {
59976
59987
  const { inputId, ariaDescribedBy } = useFieldAttributes();
59977
59988
  const { onKeyDown } = internal;
59978
59989
  const inputRef = useRef(null);
59990
+ const keepArrowDownInOpenComboBox = useKeepArrowDownInOpenComboBox();
59979
59991
  const openOnClick = useOpenOnClick({
59980
59992
  readOnly,
59981
59993
  disabled
@@ -59987,6 +59999,7 @@ var Input7 = ({ className, ...internal }) => {
59987
59999
  }, id6);
59988
60000
  return /* @__PURE__ */ React177.createElement(Input, {
59989
60001
  ref: inputRef,
60002
+ onKeyUpCapture: keepArrowDownInOpenComboBox,
59990
60003
  id: inputId,
59991
60004
  autoComplete: "country-name",
59992
60005
  "aria-describedby": ariaDescribedBy,
@@ -60264,6 +60277,7 @@ var Input8 = ({ className, ...internal }) => {
60264
60277
  const { inputId, ariaDescribedBy } = useFieldAttributes();
60265
60278
  const { onFocus } = internal;
60266
60279
  const inputRef = useRef(null);
60280
+ const keepArrowDownInOpenComboBox = useKeepArrowDownInOpenComboBox();
60267
60281
  useFocusFieldEvent(() => {
60268
60282
  inputRef.current?.focus({
60269
60283
  preventScroll: true
@@ -60272,6 +60286,7 @@ var Input8 = ({ className, ...internal }) => {
60272
60286
  useKeepPrehydrationValue(inputRef);
60273
60287
  return /* @__PURE__ */ React177.createElement(Input, {
60274
60288
  ref: inputRef,
60289
+ onKeyUpCapture: keepArrowDownInOpenComboBox,
60275
60290
  id: inputId,
60276
60291
  autoComplete: "postal-code",
60277
60292
  "aria-describedby": ariaDescribedBy,
@@ -60453,6 +60468,7 @@ var Input9 = ({ className, ...internal }) => {
60453
60468
  const { inputId, ariaDescribedBy } = useFieldAttributes();
60454
60469
  const { onFocus } = internal;
60455
60470
  const inputRef = useRef(null);
60471
+ const keepArrowDownInOpenComboBox = useKeepArrowDownInOpenComboBox();
60456
60472
  useFocusFieldEvent(() => {
60457
60473
  inputRef.current?.focus({
60458
60474
  preventScroll: true
@@ -60461,6 +60477,7 @@ var Input9 = ({ className, ...internal }) => {
60461
60477
  useKeepPrehydrationValue(inputRef);
60462
60478
  return /* @__PURE__ */ React177.createElement(Input, {
60463
60479
  ref: inputRef,
60480
+ onKeyUpCapture: keepArrowDownInOpenComboBox,
60464
60481
  id: inputId,
60465
60482
  autoComplete: "address-line1",
60466
60483
  "aria-describedby": ariaDescribedBy,
@@ -60628,6 +60645,7 @@ var Input11 = ({ className, ...internal }) => {
60628
60645
  const { inputId, ariaDescribedBy } = useFieldAttributes();
60629
60646
  const { onKeyDown } = internal;
60630
60647
  const inputRef = useRef(null);
60648
+ const keepArrowDownInOpenComboBox = useKeepArrowDownInOpenComboBox();
60631
60649
  const openOnClick = useOpenOnClick({
60632
60650
  readOnly,
60633
60651
  disabled
@@ -60639,6 +60657,7 @@ var Input11 = ({ className, ...internal }) => {
60639
60657
  }, id6);
60640
60658
  return /* @__PURE__ */ React177.createElement(Input, {
60641
60659
  ref: inputRef,
60660
+ onKeyUpCapture: keepArrowDownInOpenComboBox,
60642
60661
  id: inputId,
60643
60662
  autoComplete: "address-level1",
60644
60663
  "aria-describedby": ariaDescribedBy,
@@ -61195,6 +61214,51 @@ function isCountryMatching(country, searchPhrase) {
61195
61214
  function isSubstring(full, part) {
61196
61215
  return full.toLowerCase().includes(part.toLowerCase());
61197
61216
  }
61217
+ function useDetectedCountryCode({ currentValue, selectedCountryCode, handlePhoneChange, handleCountryCodeChange }) {
61218
+ const [detectedCountryCode, setDetectedCountryCode] = useState();
61219
+ const isTypingPhoneNumber = useRef(false);
61220
+ const settledCountryCode = useRef(selectedCountryCode);
61221
+ useEffect(() => {
61222
+ if (!currentValue) {
61223
+ isTypingPhoneNumber.current = false;
61224
+ settledCountryCode.current = selectedCountryCode;
61225
+ setDetectedCountryCode(void 0);
61226
+ return;
61227
+ }
61228
+ if (!isTypingPhoneNumber.current) {
61229
+ settledCountryCode.current = selectedCountryCode;
61230
+ return;
61231
+ }
61232
+ const settleTimeout = setTimeout(() => {
61233
+ if (settledCountryCode.current !== selectedCountryCode) {
61234
+ settledCountryCode.current = selectedCountryCode;
61235
+ setDetectedCountryCode(selectedCountryCode);
61236
+ }
61237
+ });
61238
+ return () => clearTimeout(settleTimeout);
61239
+ }, [
61240
+ currentValue,
61241
+ selectedCountryCode
61242
+ ]);
61243
+ const handleTypedPhoneChange = useCallback((value) => {
61244
+ isTypingPhoneNumber.current = true;
61245
+ handlePhoneChange(value);
61246
+ }, [
61247
+ handlePhoneChange
61248
+ ]);
61249
+ const handleSelectedCountryCodeChange = useCallback((countryCode) => {
61250
+ isTypingPhoneNumber.current = false;
61251
+ setDetectedCountryCode(void 0);
61252
+ handleCountryCodeChange(countryCode);
61253
+ }, [
61254
+ handleCountryCodeChange
61255
+ ]);
61256
+ return {
61257
+ detectedCountryCode,
61258
+ handlePhoneChange: handleTypedPhoneChange,
61259
+ handleCountryCodeChange: handleSelectedCountryCodeChange
61260
+ };
61261
+ }
61198
61262
  function usePhoneInputLogic({ value, defaultCountryCode, allowedCountryCodes, onChange }) {
61199
61263
  const [currentValue, setCurrentValue] = useState(value || "");
61200
61264
  const lastEmittedRef = useRef(normalizePhone(value ?? null) ?? "");
@@ -61316,12 +61380,14 @@ var PhoneInput = ({ children }) => {
61316
61380
  const countryCodes = useMemo(() => countries.map((country) => country.shortCountryCode), [
61317
61381
  countries
61318
61382
  ]);
61319
- const { currentValue, selectedCountryCode, handlePhoneChange, handleCountryCodeChange } = usePhoneInputLogic({
61383
+ const phoneInputLogic = usePhoneInputLogic({
61320
61384
  value,
61321
61385
  defaultCountryCode: defaultCountry,
61322
61386
  allowedCountryCodes: countryCodes,
61323
61387
  onChange
61324
61388
  });
61389
+ const { currentValue, selectedCountryCode } = phoneInputLogic;
61390
+ const { detectedCountryCode, handlePhoneChange, handleCountryCodeChange } = useDetectedCountryCode(phoneInputLogic);
61325
61391
  const labelElement = findChildOfType(children, PhoneInput.Label);
61326
61392
  const controlElement = findChildOfType(children, PhoneInput.Control);
61327
61393
  const descriptionElement = findChildOfType(children, PhoneInput.Description);
@@ -61345,10 +61411,24 @@ var PhoneInput = ({ children }) => {
61345
61411
  style: {
61346
61412
  display: "contents"
61347
61413
  }
61348
- }), controlElement),
61414
+ }), controlElement, /* @__PURE__ */ React177.createElement(DetectedCountryAnnouncement, {
61415
+ countryCode: detectedCountryCode
61416
+ })),
61349
61417
  renderDescription: () => /* @__PURE__ */ React177.createElement(React177.Fragment, null, errorElement, descriptionElement)
61350
61418
  }));
61351
61419
  };
61420
+ var DetectedCountryAnnouncement = ({ countryCode }) => {
61421
+ const { t } = useTranslation2();
61422
+ const { countries } = usePhoneInputContext();
61423
+ const country = countries.find((c) => c.shortCountryCode === countryCode);
61424
+ return /* @__PURE__ */ React177.createElement(VisuallyHidden, {
61425
+ role: "status",
61426
+ "aria-live": "polite",
61427
+ "aria-atomic": "true"
61428
+ }, country && t("field.phone.country-detected.announcement", {
61429
+ countryName: country.countryName
61430
+ }));
61431
+ };
61352
61432
  var CountryButton = ({ children, className }) => {
61353
61433
  const { labelId } = useFieldAttributes();
61354
61434
  const { hasError, disabled, readOnly } = useFieldPropsV2();