@wix/form-public 0.500.0 → 0.502.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
@@ -51077,7 +51077,8 @@ Label.Image = LabelImage;
51077
51077
 
51078
51078
  // ../form-fields/dist/esm/headless/styled/shared/use-element-state-class-name.js
51079
51079
  __toESM(require_classnames());
51080
- React172.createContext(void 0);
51080
+ var ElementPropsContext = React172.createContext(void 0);
51081
+ var useElementProps = () => React172.useContext(ElementPropsContext) ?? {};
51081
51082
  function useFocus({ onBlur, onFocus }) {
51082
51083
  const containerRef = React172.useRef(null);
51083
51084
  const isFocused = React172.useRef(false);
@@ -55153,9 +55154,27 @@ Donation.Options = Options2;
55153
55154
  Donation.OtherInput = OtherInput2;
55154
55155
  Donation.Description = Description;
55155
55156
  Donation.Error = Error2;
55157
+ var DROPDOWN_FIELD_TYPES = [
55158
+ FIELD_TYPES.DROPDOWN,
55159
+ FIELD_TYPES.DEXT_DROPDOWN,
55160
+ FIELD_TYPES.SERVICES_DROPDOWN
55161
+ ];
55162
+ var isOpenableDropdown = ({ fieldType, properties }) => DROPDOWN_FIELD_TYPES.includes(fieldType) && !properties.hidden && !properties.disabled && !properties.readOnly;
55163
+ var byLayoutPosition = (first2, second) => first2.layout.row - second.layout.row || first2.layout.column - second.layout.column;
55164
+ var useIsForcedOpenDropdown = (fieldId) => {
55165
+ const isOpenState = useElementProps().dropdown?.open === true;
55166
+ const formView = React172.useContext(FormViewContext);
55167
+ const firstDropdownId = React172.useMemo(() => formView && !formView.parentId ? formView.fields.filter(isOpenableDropdown).sort(byLayoutPosition)[0]?.id : void 0, [
55168
+ formView
55169
+ ]);
55170
+ return isOpenState && firstDropdownId === fieldId;
55171
+ };
55172
+
55173
+ // ../form-fields/dist/esm/ui/dropdown-field/dropdown-field-headless.js
55156
55174
  var Dropdown = ({ children }) => {
55157
55175
  const { id: id6, value, defaultValue, options = [], readOnly, onChange, placeholder, disabled, required, onBlur, onFocus, FieldLayout, hasError } = useFieldPropsV2();
55158
55176
  const [isOpen, setIsOpen] = React172.useState(false);
55177
+ const isForcedOpen = useIsForcedOpenDropdown(id6);
55159
55178
  const [container, setContainer] = React172.useState(null);
55160
55179
  const selectedValue = value && options.some((option2) => (option2.value ?? option2.label) === value) ? value : defaultValue || null;
55161
55180
  const { labelId } = useFieldAttributes();
@@ -55189,8 +55208,8 @@ var Dropdown = ({ children }) => {
55189
55208
  }, /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.Select, {
55190
55209
  "aria-labelledby": labelId,
55191
55210
  value: selectedValue,
55192
- isOpen: isOpen && !disabled && !readOnly,
55193
- onOpenChange: handleOpenChange,
55211
+ isOpen: isForcedOpen || isOpen && !disabled && !readOnly,
55212
+ onOpenChange: isForcedOpen ? void 0 : handleOpenChange,
55194
55213
  onChange: handleChange,
55195
55214
  isDisabled: disabled,
55196
55215
  isInvalid: hasError,
@@ -55198,7 +55217,9 @@ var Dropdown = ({ children }) => {
55198
55217
  placeholder,
55199
55218
  onBlur,
55200
55219
  onFocus
55201
- }, triggerElement, optionsElement))),
55220
+ }, triggerElement, applyInternalProps(optionsElement, {
55221
+ isForcedOpen
55222
+ })))),
55202
55223
  renderDescription: () => /* @__PURE__ */ React172__default.default.createElement(React172__default.default.Fragment, null, errorElement, descriptionElement)
55203
55224
  });
55204
55225
  };
@@ -55218,14 +55239,17 @@ var Trigger2 = ({ children, className }) => {
55218
55239
  "data-loading": isLoading || void 0
55219
55240
  }, /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.SelectValue, null), children);
55220
55241
  };
55221
- var Options3 = ({ children, className }) => {
55242
+ var Options3 = ({ children, className, ...internal }) => {
55243
+ const { isForcedOpen } = internal;
55222
55244
  const { options = [] } = useFieldPropsV2();
55223
55245
  const optionElement = findChildOfType(children, Options3.Option);
55224
55246
  return /* @__PURE__ */ React172__default.default.createElement(NonModalPopover, {
55225
55247
  className,
55226
55248
  containerPadding: 0,
55227
55249
  offset: 0
55228
- }, /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.ListBox, null, options.map((option2) => applyInternalProps(optionElement, {
55250
+ }, /* @__PURE__ */ React172__default.default.createElement(reactAriaComponents.ListBox, {
55251
+ autoFocus: isForcedOpen ? false : void 0
55252
+ }, options.map((option2) => applyInternalProps(optionElement, {
55229
55253
  key: option2.value ?? option2.label,
55230
55254
  value: option2.value ?? option2.label,
55231
55255
  label: option2.label