@wix/form-public 0.572.0 → 0.574.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.cjs CHANGED
@@ -36483,6 +36483,7 @@ var require_messages_en2 = __commonJS({
36483
36483
  "input.error.message.incomplete-date-error.month-day-time": "Enter a month, day and time.",
36484
36484
  "file-upload.aria-roledescription": "File upload",
36485
36485
  "settings.appointment.duration.minutes-label": "Minutes",
36486
+ "field.phone.country-detected.announcement": "Phone country is now {countryName}.",
36486
36487
  "contacts-phone.input.error.message.pattern-error": "Enter a valid phone number.",
36487
36488
  "mla-street-number.input.error.message.required-error": "Enter a house number.",
36488
36489
  "date-picker.a11y.dropdown-month": "Select month",
@@ -59506,6 +59507,14 @@ var OpenOnPredictions = ({ optionCount }) => {
59506
59507
  ]);
59507
59508
  return null;
59508
59509
  };
59510
+ var useKeepArrowDownInOpenComboBox = () => {
59511
+ const state = React177.useContext(reactAriaComponents.ComboBoxStateContext);
59512
+ return (event) => {
59513
+ if (event.key === "ArrowDown" && state?.isOpen) {
59514
+ event.stopPropagation();
59515
+ }
59516
+ };
59517
+ };
59509
59518
 
59510
59519
  // ../form-fields/dist/esm/ui/multiline-address-field/headless/address-line-field-headless.js
59511
59520
  var AddressLine = ({ children }) => {
@@ -59648,6 +59657,7 @@ var Input4 = ({ className, ...internal }) => {
59648
59657
  const { inputId, ariaDescribedBy } = useFieldAttributes();
59649
59658
  const { onFocus } = internal;
59650
59659
  const inputRef = React177.useRef(null);
59660
+ const keepArrowDownInOpenComboBox = useKeepArrowDownInOpenComboBox();
59651
59661
  useFocusFieldEvent(() => {
59652
59662
  inputRef.current?.focus({
59653
59663
  preventScroll: true
@@ -59656,6 +59666,7 @@ var Input4 = ({ className, ...internal }) => {
59656
59666
  useKeepPrehydrationValue(inputRef);
59657
59667
  return /* @__PURE__ */ React177__default.default.createElement(reactAriaComponents.Input, {
59658
59668
  ref: inputRef,
59669
+ onKeyUpCapture: keepArrowDownInOpenComboBox,
59659
59670
  id: inputId,
59660
59671
  autoComplete: "address-line1",
59661
59672
  "aria-describedby": ariaDescribedBy,
@@ -59986,6 +59997,7 @@ var Input7 = ({ className, ...internal }) => {
59986
59997
  const { inputId, ariaDescribedBy } = useFieldAttributes();
59987
59998
  const { onKeyDown } = internal;
59988
59999
  const inputRef = React177.useRef(null);
60000
+ const keepArrowDownInOpenComboBox = useKeepArrowDownInOpenComboBox();
59989
60001
  const openOnClick = useOpenOnClick({
59990
60002
  readOnly,
59991
60003
  disabled
@@ -59997,6 +60009,7 @@ var Input7 = ({ className, ...internal }) => {
59997
60009
  }, id6);
59998
60010
  return /* @__PURE__ */ React177__default.default.createElement(reactAriaComponents.Input, {
59999
60011
  ref: inputRef,
60012
+ onKeyUpCapture: keepArrowDownInOpenComboBox,
60000
60013
  id: inputId,
60001
60014
  autoComplete: "country-name",
60002
60015
  "aria-describedby": ariaDescribedBy,
@@ -60274,6 +60287,7 @@ var Input8 = ({ className, ...internal }) => {
60274
60287
  const { inputId, ariaDescribedBy } = useFieldAttributes();
60275
60288
  const { onFocus } = internal;
60276
60289
  const inputRef = React177.useRef(null);
60290
+ const keepArrowDownInOpenComboBox = useKeepArrowDownInOpenComboBox();
60277
60291
  useFocusFieldEvent(() => {
60278
60292
  inputRef.current?.focus({
60279
60293
  preventScroll: true
@@ -60282,6 +60296,7 @@ var Input8 = ({ className, ...internal }) => {
60282
60296
  useKeepPrehydrationValue(inputRef);
60283
60297
  return /* @__PURE__ */ React177__default.default.createElement(reactAriaComponents.Input, {
60284
60298
  ref: inputRef,
60299
+ onKeyUpCapture: keepArrowDownInOpenComboBox,
60285
60300
  id: inputId,
60286
60301
  autoComplete: "postal-code",
60287
60302
  "aria-describedby": ariaDescribedBy,
@@ -60463,6 +60478,7 @@ var Input9 = ({ className, ...internal }) => {
60463
60478
  const { inputId, ariaDescribedBy } = useFieldAttributes();
60464
60479
  const { onFocus } = internal;
60465
60480
  const inputRef = React177.useRef(null);
60481
+ const keepArrowDownInOpenComboBox = useKeepArrowDownInOpenComboBox();
60466
60482
  useFocusFieldEvent(() => {
60467
60483
  inputRef.current?.focus({
60468
60484
  preventScroll: true
@@ -60471,6 +60487,7 @@ var Input9 = ({ className, ...internal }) => {
60471
60487
  useKeepPrehydrationValue(inputRef);
60472
60488
  return /* @__PURE__ */ React177__default.default.createElement(reactAriaComponents.Input, {
60473
60489
  ref: inputRef,
60490
+ onKeyUpCapture: keepArrowDownInOpenComboBox,
60474
60491
  id: inputId,
60475
60492
  autoComplete: "address-line1",
60476
60493
  "aria-describedby": ariaDescribedBy,
@@ -60638,6 +60655,7 @@ var Input11 = ({ className, ...internal }) => {
60638
60655
  const { inputId, ariaDescribedBy } = useFieldAttributes();
60639
60656
  const { onKeyDown } = internal;
60640
60657
  const inputRef = React177.useRef(null);
60658
+ const keepArrowDownInOpenComboBox = useKeepArrowDownInOpenComboBox();
60641
60659
  const openOnClick = useOpenOnClick({
60642
60660
  readOnly,
60643
60661
  disabled
@@ -60649,6 +60667,7 @@ var Input11 = ({ className, ...internal }) => {
60649
60667
  }, id6);
60650
60668
  return /* @__PURE__ */ React177__default.default.createElement(reactAriaComponents.Input, {
60651
60669
  ref: inputRef,
60670
+ onKeyUpCapture: keepArrowDownInOpenComboBox,
60652
60671
  id: inputId,
60653
60672
  autoComplete: "address-level1",
60654
60673
  "aria-describedby": ariaDescribedBy,
@@ -61205,6 +61224,51 @@ function isCountryMatching(country, searchPhrase) {
61205
61224
  function isSubstring(full, part) {
61206
61225
  return full.toLowerCase().includes(part.toLowerCase());
61207
61226
  }
61227
+ function useDetectedCountryCode({ currentValue, selectedCountryCode, handlePhoneChange, handleCountryCodeChange }) {
61228
+ const [detectedCountryCode, setDetectedCountryCode] = React177.useState();
61229
+ const isTypingPhoneNumber = React177.useRef(false);
61230
+ const settledCountryCode = React177.useRef(selectedCountryCode);
61231
+ React177.useEffect(() => {
61232
+ if (!currentValue) {
61233
+ isTypingPhoneNumber.current = false;
61234
+ settledCountryCode.current = selectedCountryCode;
61235
+ setDetectedCountryCode(void 0);
61236
+ return;
61237
+ }
61238
+ if (!isTypingPhoneNumber.current) {
61239
+ settledCountryCode.current = selectedCountryCode;
61240
+ return;
61241
+ }
61242
+ const settleTimeout = setTimeout(() => {
61243
+ if (settledCountryCode.current !== selectedCountryCode) {
61244
+ settledCountryCode.current = selectedCountryCode;
61245
+ setDetectedCountryCode(selectedCountryCode);
61246
+ }
61247
+ });
61248
+ return () => clearTimeout(settleTimeout);
61249
+ }, [
61250
+ currentValue,
61251
+ selectedCountryCode
61252
+ ]);
61253
+ const handleTypedPhoneChange = React177.useCallback((value) => {
61254
+ isTypingPhoneNumber.current = true;
61255
+ handlePhoneChange(value);
61256
+ }, [
61257
+ handlePhoneChange
61258
+ ]);
61259
+ const handleSelectedCountryCodeChange = React177.useCallback((countryCode) => {
61260
+ isTypingPhoneNumber.current = false;
61261
+ setDetectedCountryCode(void 0);
61262
+ handleCountryCodeChange(countryCode);
61263
+ }, [
61264
+ handleCountryCodeChange
61265
+ ]);
61266
+ return {
61267
+ detectedCountryCode,
61268
+ handlePhoneChange: handleTypedPhoneChange,
61269
+ handleCountryCodeChange: handleSelectedCountryCodeChange
61270
+ };
61271
+ }
61208
61272
  function usePhoneInputLogic({ value, defaultCountryCode, allowedCountryCodes, onChange }) {
61209
61273
  const [currentValue, setCurrentValue] = React177.useState(value || "");
61210
61274
  const lastEmittedRef = React177.useRef(normalizePhone(value ?? null) ?? "");
@@ -61326,12 +61390,14 @@ var PhoneInput = ({ children }) => {
61326
61390
  const countryCodes = React177.useMemo(() => countries.map((country) => country.shortCountryCode), [
61327
61391
  countries
61328
61392
  ]);
61329
- const { currentValue, selectedCountryCode, handlePhoneChange, handleCountryCodeChange } = usePhoneInputLogic({
61393
+ const phoneInputLogic = usePhoneInputLogic({
61330
61394
  value,
61331
61395
  defaultCountryCode: defaultCountry,
61332
61396
  allowedCountryCodes: countryCodes,
61333
61397
  onChange
61334
61398
  });
61399
+ const { currentValue, selectedCountryCode } = phoneInputLogic;
61400
+ const { detectedCountryCode, handlePhoneChange, handleCountryCodeChange } = useDetectedCountryCode(phoneInputLogic);
61335
61401
  const labelElement = findChildOfType(children, PhoneInput.Label);
61336
61402
  const controlElement = findChildOfType(children, PhoneInput.Control);
61337
61403
  const descriptionElement = findChildOfType(children, PhoneInput.Description);
@@ -61355,10 +61421,24 @@ var PhoneInput = ({ children }) => {
61355
61421
  style: {
61356
61422
  display: "contents"
61357
61423
  }
61358
- }), controlElement),
61424
+ }), controlElement, /* @__PURE__ */ React177__default.default.createElement(DetectedCountryAnnouncement, {
61425
+ countryCode: detectedCountryCode
61426
+ })),
61359
61427
  renderDescription: () => /* @__PURE__ */ React177__default.default.createElement(React177__default.default.Fragment, null, errorElement, descriptionElement)
61360
61428
  }));
61361
61429
  };
61430
+ var DetectedCountryAnnouncement = ({ countryCode }) => {
61431
+ const { t } = useTranslation2();
61432
+ const { countries } = usePhoneInputContext();
61433
+ const country = countries.find((c) => c.shortCountryCode === countryCode);
61434
+ return /* @__PURE__ */ React177__default.default.createElement(reactAriaComponents.VisuallyHidden, {
61435
+ role: "status",
61436
+ "aria-live": "polite",
61437
+ "aria-atomic": "true"
61438
+ }, country && t("field.phone.country-detected.announcement", {
61439
+ countryName: country.countryName
61440
+ }));
61441
+ };
61362
61442
  var CountryButton = ({ children, className }) => {
61363
61443
  const { labelId } = useFieldAttributes();
61364
61444
  const { hasError, disabled, readOnly } = useFieldPropsV2();