@wix/form-public 0.503.0 → 0.504.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
@@ -53744,6 +53744,49 @@ var DatePickerTriggerButton = /* @__PURE__ */ React172.forwardRef((props2, ref)
53744
53744
  onPress: handlePress
53745
53745
  });
53746
53746
  });
53747
+ var DROPDOWN_FIELD_TYPES = [
53748
+ FIELD_TYPES.DROPDOWN,
53749
+ FIELD_TYPES.DEXT_DROPDOWN,
53750
+ FIELD_TYPES.SERVICES_DROPDOWN,
53751
+ FIELD_TYPES.DATE_INPUT,
53752
+ FIELD_TYPES.CONTACTS_BIRTHDATE,
53753
+ FIELD_TYPES.DATE_TIME_INPUT,
53754
+ FIELD_TYPES.DEXT_DATE_TIME_INPUT
53755
+ ];
53756
+ var PHONE_FIELD_TYPES = [
53757
+ FIELD_TYPES.PHONE,
53758
+ FIELD_TYPES.CONTACTS_PHONE,
53759
+ FIELD_TYPES.BOOKINGS_PHONE,
53760
+ FIELD_TYPES.DEXT_PHONE
53761
+ ];
53762
+ var ADDRESS_FIELD_TYPES = [
53763
+ FIELD_TYPES.MULTILINE_ADDRESS,
53764
+ FIELD_TYPES.BOOKINGS_ADDRESS,
53765
+ FIELD_TYPES.ECOM_ADDRESS
53766
+ ];
53767
+ var hasCountryOptions = ({ properties }) => properties.validation?.string?.phoneOptions?.allowedCountryCodes?.length !== 1;
53768
+ var showsCountry = ({ properties }) => properties.fieldSettings?.country?.show !== false;
53769
+ var hasDropdown = (field, isMobile2) => {
53770
+ if (PHONE_FIELD_TYPES.includes(field.fieldType)) {
53771
+ return !isMobile2 && hasCountryOptions(field);
53772
+ }
53773
+ if (ADDRESS_FIELD_TYPES.includes(field.fieldType)) {
53774
+ return showsCountry(field);
53775
+ }
53776
+ return DROPDOWN_FIELD_TYPES.includes(field.fieldType);
53777
+ };
53778
+ var isOpenableDropdown = (field, isMobile2) => hasDropdown(field, isMobile2) && !field.properties.hidden && !field.properties.disabled && !field.properties.readOnly;
53779
+ var byLayoutPosition = (first2, second) => first2.layout.row - second.layout.row || first2.layout.column - second.layout.column;
53780
+ var useIsForcedOpenDropdown = (fieldId) => {
53781
+ const isOpenState = useElementProps().dropdown?.open === true;
53782
+ const formView = React172.useContext(FormViewContext);
53783
+ const { isMobile: isMobile2 = false } = useConfig();
53784
+ const firstDropdownId = React172.useMemo(() => formView && !formView.parentId ? formView.fields.filter((field) => isOpenableDropdown(field, isMobile2)).sort(byLayoutPosition)[0]?.id : void 0, [
53785
+ formView,
53786
+ isMobile2
53787
+ ]);
53788
+ return isOpenState && firstDropdownId === fieldId;
53789
+ };
53747
53790
 
53748
53791
  // ../form-fields/dist/esm/ui/date-input-field/date-input-field-headless.js
53749
53792
  var DateInput = ({ children, className }) => {
@@ -53779,11 +53822,12 @@ var DateInput = ({ children, className }) => {
53779
53822
  });
53780
53823
  };
53781
53824
  var Month = ({ children, className }) => {
53782
- const { disabled, readOnly, showDateLabels, hidePlaceholder } = useFieldPropsV2();
53825
+ const { id: id6, disabled, readOnly, showDateLabels, hidePlaceholder } = useFieldPropsV2();
53783
53826
  const { labelId } = useDateFieldAttributes(SupportedDateParts.MONTH);
53784
53827
  const { partValue, partError, onPartChange } = useDatePart(SupportedDateParts.MONTH);
53785
53828
  const { t } = useTranslation2();
53786
53829
  const [isOpen, setIsOpen] = React172.useState(false);
53830
+ const isForcedOpen = useIsForcedOpenDropdown(id6);
53787
53831
  const [container, setContainer] = React172.useState(null);
53788
53832
  const placeholder = hidePlaceholder ? void 0 : t("field.date.placeholder.month");
53789
53833
  const handleMonthChange = React172.useCallback((selectedValue) => {
@@ -53820,9 +53864,11 @@ var Month = ({ children, className }) => {
53820
53864
  isDisabled: disabled,
53821
53865
  isInvalid: partError,
53822
53866
  placeholder,
53823
- isOpen,
53824
- onOpenChange: handleOpenChange
53825
- }, triggerElement, optionsElement)));
53867
+ isOpen: isForcedOpen || isOpen,
53868
+ onOpenChange: isForcedOpen ? void 0 : handleOpenChange
53869
+ }, triggerElement, applyInternalProps(optionsElement, {
53870
+ isForcedOpen
53871
+ }))));
53826
53872
  };
53827
53873
  var MonthLabel = ({ className }) => {
53828
53874
  return /* @__PURE__ */ React172__default.default.createElement(DateLabel, {
@@ -53849,7 +53895,8 @@ var MonthTrigger = ({ children, className }) => {
53849
53895
  "data-readonly": readOnly || void 0
53850
53896
  }, /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.SelectValue, null), children);
53851
53897
  };
53852
- var MonthOptions = ({ children, className }) => {
53898
+ var MonthOptions = ({ children, className, ...internal }) => {
53899
+ const { isForcedOpen } = internal;
53853
53900
  const { language } = useConfig();
53854
53901
  const months = React172.useMemo(() => getMonthList(language), [
53855
53902
  language
@@ -53859,7 +53906,9 @@ var MonthOptions = ({ children, className }) => {
53859
53906
  className,
53860
53907
  containerPadding: 0,
53861
53908
  offset: 0
53862
- }, /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.ListBox, null, months.map((month, index2) => applyInternalProps(optionElement, {
53909
+ }, /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.ListBox, {
53910
+ autoFocus: isForcedOpen ? false : void 0
53911
+ }, months.map((month, index2) => applyInternalProps(optionElement, {
53863
53912
  key: String(index2 + 1),
53864
53913
  value: String(index2 + 1),
53865
53914
  label: month
@@ -54359,11 +54408,12 @@ var DateTimeInput = ({ children, className }) => {
54359
54408
  });
54360
54409
  };
54361
54410
  var Month2 = ({ children, className }) => {
54362
- const { disabled, readOnly, showDateLabels, hidePlaceholder } = useFieldPropsV2();
54411
+ const { id: id6, disabled, readOnly, showDateLabels, hidePlaceholder } = useFieldPropsV2();
54363
54412
  const { labelId } = useDateTimeFieldAttributes(SupportedDateParts.MONTH);
54364
54413
  const { partValue, partError, onPartChange } = useFieldPart(SupportedDateParts.MONTH);
54365
54414
  const { t } = useTranslation2();
54366
54415
  const [isOpen, setIsOpen] = React172.useState(false);
54416
+ const isForcedOpen = useIsForcedOpenDropdown(id6);
54367
54417
  const [container, setContainer] = React172.useState(null);
54368
54418
  const placeholder = hidePlaceholder ? void 0 : t("field.date.placeholder.month");
54369
54419
  const handleMonthChange = React172.useCallback((selectedValue) => {
@@ -54400,9 +54450,11 @@ var Month2 = ({ children, className }) => {
54400
54450
  isDisabled: disabled,
54401
54451
  isInvalid: partError,
54402
54452
  placeholder,
54403
- isOpen,
54404
- onOpenChange: handleOpenChange
54405
- }, triggerElement, optionsElement)));
54453
+ isOpen: isForcedOpen || isOpen,
54454
+ onOpenChange: isForcedOpen ? void 0 : handleOpenChange
54455
+ }, triggerElement, applyInternalProps(optionsElement, {
54456
+ isForcedOpen
54457
+ }))));
54406
54458
  };
54407
54459
  var MonthLabel2 = ({ className }) => {
54408
54460
  return /* @__PURE__ */ React172__default.default.createElement(DateTimeLabel, {
@@ -54429,7 +54481,8 @@ var MonthTrigger3 = ({ children, className }) => {
54429
54481
  "data-readonly": readOnly || void 0
54430
54482
  }, /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.SelectValue, null), children);
54431
54483
  };
54432
- var MonthOptions2 = ({ children, className }) => {
54484
+ var MonthOptions2 = ({ children, className, ...internal }) => {
54485
+ const { isForcedOpen } = internal;
54433
54486
  const { language } = useConfig();
54434
54487
  const months = React172.useMemo(() => getMonthList(language), [
54435
54488
  language
@@ -54439,7 +54492,9 @@ var MonthOptions2 = ({ children, className }) => {
54439
54492
  className,
54440
54493
  containerPadding: 0,
54441
54494
  offset: 0
54442
- }, /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.ListBox, null, months.map((month, index2) => applyInternalProps(optionElement, {
54495
+ }, /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.ListBox, {
54496
+ autoFocus: isForcedOpen ? false : void 0
54497
+ }, months.map((month, index2) => applyInternalProps(optionElement, {
54443
54498
  key: String(index2 + 1),
54444
54499
  value: String(index2 + 1),
54445
54500
  label: month
@@ -55177,23 +55232,6 @@ Donation.Options = Options2;
55177
55232
  Donation.OtherInput = OtherInput2;
55178
55233
  Donation.Description = Description;
55179
55234
  Donation.Error = Error2;
55180
- var DROPDOWN_FIELD_TYPES = [
55181
- FIELD_TYPES.DROPDOWN,
55182
- FIELD_TYPES.DEXT_DROPDOWN,
55183
- FIELD_TYPES.SERVICES_DROPDOWN
55184
- ];
55185
- var isOpenableDropdown = ({ fieldType, properties }) => DROPDOWN_FIELD_TYPES.includes(fieldType) && !properties.hidden && !properties.disabled && !properties.readOnly;
55186
- var byLayoutPosition = (first2, second) => first2.layout.row - second.layout.row || first2.layout.column - second.layout.column;
55187
- var useIsForcedOpenDropdown = (fieldId) => {
55188
- const isOpenState = useElementProps().dropdown?.open === true;
55189
- const formView = React172.useContext(FormViewContext);
55190
- const firstDropdownId = React172.useMemo(() => formView && !formView.parentId ? formView.fields.filter(isOpenableDropdown).sort(byLayoutPosition)[0]?.id : void 0, [
55191
- formView
55192
- ]);
55193
- return isOpenState && firstDropdownId === fieldId;
55194
- };
55195
-
55196
- // ../form-fields/dist/esm/ui/dropdown-field/dropdown-field-headless.js
55197
55235
  var Dropdown = ({ children }) => {
55198
55236
  const { id: id6, value, defaultValue, options = [], readOnly, onChange, placeholder, disabled, required, onBlur, onFocus, FieldLayout, hasError } = useFieldPropsV2();
55199
55237
  const [isOpen, setIsOpen] = React172.useState(false);
@@ -57776,6 +57814,26 @@ City.Error = Error2;
57776
57814
 
57777
57815
  // ../form-fields/dist/esm/ui/multiline-address-field/headless/country-field-headless.js
57778
57816
  init_esm2();
57817
+ var KeepComboBoxOpen = ({ isOpen }) => {
57818
+ const state = React172.useContext(reactAriaComponents.ComboBoxStateContext);
57819
+ const wasOpen = React172.useRef(false);
57820
+ React172.useEffect(() => {
57821
+ if (isOpen && state && !state.isOpen) {
57822
+ state.open(null, "manual");
57823
+ }
57824
+ if (isOpen && state?.selectionManager.focusedKey != null) {
57825
+ state.selectionManager.setFocusedKey(null);
57826
+ }
57827
+ if (!isOpen && wasOpen.current) {
57828
+ state?.close();
57829
+ }
57830
+ wasOpen.current = isOpen;
57831
+ }, [
57832
+ isOpen,
57833
+ state
57834
+ ]);
57835
+ return null;
57836
+ };
57779
57837
  var useOpenOnClick = ({ readOnly, disabled } = {}) => {
57780
57838
  const state = React172.useContext(reactAriaComponents.ComboBoxStateContext);
57781
57839
  return React172.useCallback(() => {
@@ -57861,7 +57919,8 @@ var useOptionComboBox = ({ options, value, commit, clear, onBlur }) => {
57861
57919
  };
57862
57920
 
57863
57921
  // ../form-fields/dist/esm/ui/multiline-address-field/headless/country-field-headless.js
57864
- var Country = ({ children }) => {
57922
+ var Country = ({ children, ...internal }) => {
57923
+ const { isForcedOpen = false } = internal;
57865
57924
  const { id: id6, value, onChange, disabled, readOnly, required, hasError, onBlur, onFocus, FieldLayout, options } = useFieldPropsV2();
57866
57925
  const { labelId } = useFieldAttributes();
57867
57926
  const { t } = useTranslation2();
@@ -57916,6 +57975,8 @@ var Country = ({ children }) => {
57916
57975
  onKeyDown: onInputKeyDown
57917
57976
  }), applyInternalProps(optionsElement, {
57918
57977
  options: countryOptions
57978
+ }), /* @__PURE__ */ React172__default.default.createElement(KeepComboBoxOpen, {
57979
+ isOpen: isForcedOpen
57919
57980
  })),
57920
57981
  renderDescription: () => /* @__PURE__ */ React172__default.default.createElement(React172__default.default.Fragment, null, errorElement, descriptionElement)
57921
57982
  });
@@ -58698,7 +58759,10 @@ var MultilineAddress = ({ children }) => {
58698
58759
  const field = form?.fields?.find((f) => "target" in f && f.target === firstError?.errorPath);
58699
58760
  return field?.id;
58700
58761
  });
58701
- const countryElement = findChildOfType(children, MultilineAddress.Country);
58762
+ const isForcedOpen = useIsForcedOpenDropdown(id6);
58763
+ const countryElement = applyInternalProps(findChildOfType(children, MultilineAddress.Country), {
58764
+ isForcedOpen
58765
+ });
58702
58766
  const subdivisionElement = findChildOfType(children, MultilineAddress.Subdivision);
58703
58767
  const cityElement = findChildOfType(children, MultilineAddress.City);
58704
58768
  const addressLineElement = findChildOfType(children, MultilineAddress.AddressLine);
@@ -59220,10 +59284,12 @@ var CountryButtonEmptyState = ({ children, className }) => {
59220
59284
  CountryButton.Flag = CountryButtonFlag;
59221
59285
  CountryButton.EmptyState = CountryButtonEmptyState;
59222
59286
  var CountryOptions = ({ children, className, "aria-label": ariaLabel, placement, offset, ...internal }) => {
59223
- const { triggerRef, optionsRef } = internal;
59287
+ const { triggerRef, optionsRef, isForcedOpen } = internal;
59224
59288
  const { popoverContainer } = usePhoneInputContext();
59225
59289
  const searchElement = findChildOfType(children, CountryOptions.Search);
59226
- const content = /* @__PURE__ */ React172__default.default.createElement(CountryOptionsContent, null, children);
59290
+ const content = /* @__PURE__ */ React172__default.default.createElement(CountryOptionsContent, {
59291
+ isForcedOpen
59292
+ }, children);
59227
59293
  return /* @__PURE__ */ React172__default.default.createElement($72abaeab4d80592f$export$78efe591171d7d45, {
59228
59294
  getContainer: () => popoverContainer
59229
59295
  }, /* @__PURE__ */ React172__default.default.createElement(NonModalPopover, {
@@ -59233,7 +59299,7 @@ var CountryOptions = ({ children, className, "aria-label": ariaLabel, placement,
59233
59299
  placement,
59234
59300
  offset,
59235
59301
  containerPadding: 0
59236
- }, searchElement ? /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Dialog, {
59302
+ }, searchElement && !isForcedOpen ? /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Dialog, {
59237
59303
  "aria-label": ariaLabel
59238
59304
  }, content) : content));
59239
59305
  };
@@ -59263,7 +59329,7 @@ var CountryOptionsModal = ({ children, className, overlayClassName, "aria-label"
59263
59329
  }
59264
59330
  }, children)))));
59265
59331
  };
59266
- var CountryOptionsContent = ({ children, listBoxProps }) => {
59332
+ var CountryOptionsContent = ({ children, listBoxProps, isForcedOpen }) => {
59267
59333
  const { countries } = usePhoneInputContext();
59268
59334
  const optionElement = findChildOfType(children, CountryOptions.Option);
59269
59335
  const searchElement = findChildOfType(children, CountryOptions.Search);
@@ -59286,16 +59352,20 @@ var CountryOptionsContent = ({ children, listBoxProps }) => {
59286
59352
  const country = countries.find((item) => item.shortCountryCode === node.key);
59287
59353
  return !!country && isCountryMatching(country, query);
59288
59354
  }
59289
- }, searchElement, listbox) : listbox;
59355
+ }, isForcedOpen ? applyInternalProps(searchElement, {
59356
+ autoFocus: false
59357
+ }) : searchElement, listbox) : listbox;
59290
59358
  };
59291
59359
  CountryOptions.Popover = CountryOptions;
59292
59360
  CountryOptions.Modal = CountryOptionsModal;
59293
- var CountrySearch = ({ className, children, "aria-label": ariaLabel }) => {
59361
+ var CountrySearch = ({ className, children, "aria-label": ariaLabel, ...internal }) => {
59362
+ const { autoFocus = true } = internal;
59294
59363
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.SearchField, {
59295
- className,
59296
59364
  "aria-label": ariaLabel,
59297
- autoFocus: true
59298
- }, children);
59365
+ autoFocus
59366
+ }, /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Group, {
59367
+ className
59368
+ }, children));
59299
59369
  };
59300
59370
  var CountrySearchInput = ({ className, placeholder }) => /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Input, {
59301
59371
  className,
@@ -59378,7 +59448,8 @@ var Control7 = ({ children, className }) => {
59378
59448
  const controlRef = React172.useRef(null);
59379
59449
  const optionsRef = React172.useRef(null);
59380
59450
  const isFocused = React172.useRef(false);
59381
- const { disabled, readOnly, required, hasError, showFlag, onFocus, onBlur } = useFieldPropsV2();
59451
+ const { id: id6, disabled, readOnly, required, hasError, showFlag, onFocus, onBlur } = useFieldPropsV2();
59452
+ const [isOpen, setIsOpen] = React172.useState(false);
59382
59453
  const invokeBlur = useInvokeCallback(onBlur);
59383
59454
  const { t } = useTranslation2();
59384
59455
  const { selectedCountryCode, handleCountryCodeChange, countries } = usePhoneInputContext();
@@ -59386,6 +59457,11 @@ var Control7 = ({ children, className }) => {
59386
59457
  const modalElement = findChildOfType(children, PhoneInput.CountryOptions.Modal);
59387
59458
  const countryOptionsElement = modalElement ?? findChildOfType(children, PhoneInput.CountryOptions.Popover);
59388
59459
  const phoneNumberElement = findChildOfType(children, PhoneInput.PhoneNumber);
59460
+ const hasCountryOptions2 = countries.length > 1;
59461
+ const isForcedOpen = useIsForcedOpenDropdown(id6) && !modalElement && hasCountryOptions2;
59462
+ const controlClassName = typeof className === "function" ? className({
59463
+ hasCountryOptions: hasCountryOptions2
59464
+ }) : className;
59389
59465
  const focusHandlers = {
59390
59466
  onFocus: () => {
59391
59467
  if (!isFocused.current) {
@@ -59404,7 +59480,7 @@ var Control7 = ({ children, className }) => {
59404
59480
  if (countries.length === 1) {
59405
59481
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Group, {
59406
59482
  ref: controlRef,
59407
- className,
59483
+ className: controlClassName,
59408
59484
  isDisabled: disabled,
59409
59485
  isInvalid: hasError,
59410
59486
  ...focusHandlers
@@ -59414,11 +59490,12 @@ var Control7 = ({ children, className }) => {
59414
59490
  }
59415
59491
  const selector = /* @__PURE__ */ React172__default.default.createElement(React172__default.default.Fragment, null, countryButtonElement, applyInternalProps(countryOptionsElement, {
59416
59492
  triggerRef: controlRef,
59417
- optionsRef
59493
+ optionsRef,
59494
+ isForcedOpen
59418
59495
  }));
59419
59496
  return /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Group, {
59420
59497
  ref: controlRef,
59421
- className,
59498
+ className: controlClassName,
59422
59499
  isDisabled: disabled,
59423
59500
  isInvalid: hasError,
59424
59501
  ...focusHandlers
@@ -59429,7 +59506,9 @@ var Control7 = ({ children, className }) => {
59429
59506
  isDisabled: disabled || readOnly,
59430
59507
  isInvalid: hasError,
59431
59508
  isRequired: required,
59432
- placeholder: ""
59509
+ placeholder: "",
59510
+ isOpen: isForcedOpen || isOpen && !disabled && !readOnly,
59511
+ onOpenChange: isForcedOpen ? void 0 : setIsOpen
59433
59512
  }, selector), phoneNumberElement);
59434
59513
  };
59435
59514
  PhoneInput.Label = Label;