x-ui-design 0.4.76 → 0.4.78

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.
@@ -18,7 +18,7 @@ export interface FieldData {
18
18
  value?: RuleTypes;
19
19
  errors?: string[];
20
20
  }
21
- export type FieldInstancesInputRef = HTMLInputElement | null;
21
+ export type FieldInstancesInputRef = HTMLInputElement | HTMLDivElement | null;
22
22
  export type FieldInstancesRef = {
23
23
  input?: FieldInstancesInputRef;
24
24
  };
@@ -87,7 +87,7 @@ export interface FormInstance {
87
87
  setFields: (fields: FieldData[]) => void;
88
88
  resetFields: (nameList?: string[], showError?: boolean | null) => void;
89
89
  getFieldError: (name: string) => string[];
90
- registerField: (name: string, rules?: RuleObject[], remove?: boolean, fieldRef?: FieldInstancesRef) => void;
90
+ registerField: (name: string, rules?: RuleObject[], remove?: boolean, fieldRef?: FieldInstancesRef | null) => void;
91
91
  setFieldValue: (name: string, value: RuleTypes, errors?: string[], reset?: boolean | null | undefined, touch?: boolean) => void;
92
92
  getFieldValue: (name: string) => RuleTypes;
93
93
  validateFields: (nameList?: string[]) => Promise<boolean>;
package/dist/index.esm.js CHANGED
@@ -714,6 +714,9 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
714
714
  if (remove) {
715
715
  delete formRef.current[stepRef.current]?.[name];
716
716
  delete rulesRef.current[name];
717
+ if (fieldInstancesRef.current[name]) {
718
+ delete fieldInstancesRef.current[name];
719
+ }
717
720
  } else {
718
721
  if (!(name in formRef.current[stepRef.current])) {
719
722
  formRef.current[stepRef.current][name] = initialValues?.[name];
@@ -1006,7 +1009,7 @@ const FormItem$1 = ({
1006
1009
  const childrenList = useMemo(() => flattenChildren(children), [children]);
1007
1010
  useEffect(() => {
1008
1011
  if (name && !getFieldInstance(name)) {
1009
- registerField(name, rules, false, fieldRef.current ?? undefined);
1012
+ registerField(name, rules, false, fieldRef.current);
1010
1013
  }
1011
1014
  // eslint-disable-next-line react-hooks/exhaustive-deps
1012
1015
  }, [name, rules, fieldRef.current]);
@@ -1031,19 +1034,9 @@ const FormItem$1 = ({
1031
1034
  }, [dependencies, name]);
1032
1035
  const isRequired = useMemo(() => rules.some(rule => rule.required), [rules]);
1033
1036
  const errorMessage = getFieldError(name)?.[0];
1034
- const mergeRefs = elementRef => {
1035
- return el => {
1036
- fieldRef.current = el;
1037
- if (typeof elementRef === 'function') {
1038
- elementRef(el);
1039
- } else if (elementRef && typeof elementRef === 'object') {
1040
- // @ts-ignore
1041
- elementRef.current = el;
1042
- }
1043
- };
1044
- };
1045
1037
  return /*#__PURE__*/React.createElement("div", {
1046
1038
  style: style,
1039
+ ref: fieldRef,
1047
1040
  className: clsx([`${prefixCls}`, {
1048
1041
  [layout]: layout,
1049
1042
  [className]: className,
@@ -1064,11 +1057,7 @@ const FormItem$1 = ({
1064
1057
  ...childProps
1065
1058
  } = child.props;
1066
1059
  const fieldValue = value ?? getFieldValue(name) ?? initialValue;
1067
- return /*#__PURE__*/React.createElement("div", {
1068
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1069
- // @ts-expect-error
1070
- ref: mergeRefs(child.ref)
1071
- }, /*#__PURE__*/React.createElement(FormItemChildComponent, _extends({}, props, {
1060
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(FormItemChildComponent, _extends({}, props, {
1072
1061
  key: `${key}_${isReseting}`,
1073
1062
  name: name,
1074
1063
  child: child,