x-ui-design 0.3.76 → 0.3.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.
package/dist/index.esm.js CHANGED
@@ -607,6 +607,7 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
607
607
  ...initialValues
608
608
  });
609
609
  const fieldInstancesRef = useRef({});
610
+ const [isSubmit, setIsSubmit] = useState(false);
610
611
  const [isReseting, setIsReseting] = useState(false);
611
612
  const [errors, setErrors] = useState({});
612
613
  const fieldSubscribers = useRef({});
@@ -738,10 +739,16 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
738
739
  [name]: fieldErrors
739
740
  }));
740
741
  warningsRef.current[name] = fieldWarnings;
741
- if (_scrollToFirstError.current) {
742
+ console.log({
743
+ isSubmit,
744
+ _scrollToFirstError: _scrollToFirstError.current
745
+ });
746
+ if (isSubmit || _scrollToFirstError.current) {
742
747
  const firstErrorContent = document.querySelectorAll('.xUi-form-item-error')?.[0];
743
748
  if (firstErrorContent) {
744
- firstErrorContent.closest('.xUi-form-item')?.scrollIntoView();
749
+ firstErrorContent.closest('.xUi-form-item')?.closest('[data-item="first-content"]')?.scrollIntoView();
750
+ setIsSubmit(false);
751
+ setScrollToFirstError(false);
745
752
  }
746
753
  }
747
754
  return fieldErrors.length === 0;
@@ -774,6 +781,7 @@ const useForm = (initialValues = {}, onFieldsChange, onValuesChange, scrollToFir
774
781
  setIsReseting(prev => !prev);
775
782
  }
776
783
  async function submit() {
784
+ setIsSubmit(true);
777
785
  return (await validateFields()) ? formRef.current : undefined;
778
786
  }
779
787
  function subscribeToField(name, callback) {
@@ -1106,12 +1114,12 @@ const Form$1 = ({
1106
1114
  scrollToFirstError = false,
1107
1115
  ...rest
1108
1116
  }) => {
1109
- const internalForm = useForm(initialValues, onFieldsChange, onValuesChange, scrollToFirstError);
1117
+ const internalForm = useForm(initialValues, onFieldsChange, onValuesChange);
1110
1118
  const formInstance = form || internalForm;
1111
- formInstance.setScrollToFirstError(scrollToFirstError);
1112
1119
  const formRef = useRef(null);
1113
1120
  const handleSubmit = async e => {
1114
1121
  e.preventDefault();
1122
+ formInstance.setScrollToFirstError(scrollToFirstError);
1115
1123
  if (await formInstance.validateFields()) {
1116
1124
  onFinish?.(formInstance.getFieldsValue());
1117
1125
  } else if (onFinishFailed) {
@@ -1131,14 +1139,16 @@ const Form$1 = ({
1131
1139
  formInstance.onValuesChange = onValuesChange;
1132
1140
  }
1133
1141
  }, [formInstance, onFieldsChange, onValuesChange]);
1134
- const injectPropsIntoFinalLeaf = child => {
1142
+ const injectPropsIntoFinalLeaf = (child, key) => {
1135
1143
  if (! /*#__PURE__*/isValidElement(child)) {
1136
1144
  return child;
1137
1145
  }
1138
1146
  const childProps = child.props;
1139
1147
  const isWrapper = typeof child.type === 'string' && !('dangerouslySetInnerHTML' in childProps) && ['div', 'span', 'label'].includes(child.type);
1140
1148
  if (isWrapper) {
1141
- return /*#__PURE__*/React$1.createElement(child.type, childProps, Children.map(flattenChildren(childProps.children), injectPropsIntoFinalLeaf));
1149
+ return /*#__PURE__*/React$1.createElement(child.type, _extends({}, childProps, {
1150
+ "data-item": key == 0 ? 'first-content' : ''
1151
+ }), Children.map(flattenChildren(childProps.children), injectPropsIntoFinalLeaf));
1142
1152
  }
1143
1153
  if (childProps?.__injected) {
1144
1154
  return child;
@@ -1156,7 +1166,7 @@ const Form$1 = ({
1156
1166
  ref: formRef,
1157
1167
  onSubmit: handleSubmit,
1158
1168
  className: `${prefixCls} ${className}`
1159
- }, Children.map(childrenList, child => injectPropsIntoFinalLeaf(child))));
1169
+ }, Children.map(childrenList, (child, key) => injectPropsIntoFinalLeaf(child, key))));
1160
1170
  };
1161
1171
  Form$1.Item = FormItem$1;
1162
1172