@bigbinary/neetoui 5.1.7 → 5.1.9

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/formik.cjs.js CHANGED
@@ -17733,6 +17733,15 @@ var getErrorFieldName = function getErrorFieldName(formikErrors) {
17733
17733
  var _transformObjectToDot;
17734
17734
  return (_transformObjectToDot = transformObjectToDotNotation(formikErrors)) === null || _transformObjectToDot === void 0 ? void 0 : _transformObjectToDot[0];
17735
17735
  };
17736
+ var scrollToError = function scrollToError(formRef, errors) {
17737
+ var fieldErrorName = getErrorFieldName(errors);
17738
+ if (!fieldErrorName) return;
17739
+ var errorFormElement = formRef.current.querySelector("[name=\"".concat(fieldErrorName, "\"]"));
17740
+ errorFormElement === null || errorFormElement === void 0 ? void 0 : errorFormElement.scrollIntoView({
17741
+ behavior: "smooth",
17742
+ block: "center"
17743
+ });
17744
+ };
17736
17745
 
17737
17746
  var ScrollToErrorField = function ScrollToErrorField(_ref) {
17738
17747
  var formRef = _ref.formRef;
@@ -17740,26 +17749,15 @@ var ScrollToErrorField = function ScrollToErrorField(_ref) {
17740
17749
  submitCount = _useFormikContext.submitCount,
17741
17750
  isValid = _useFormikContext.isValid,
17742
17751
  errors = _useFormikContext.errors;
17743
- var isValidatedReference = React.useRef(false);
17744
17752
  React.useEffect(function () {
17745
- isValidatedReference.current = false;
17753
+ if (!formRef.current || isValid) return;
17754
+ scrollToError(formRef, errors);
17746
17755
  }, [submitCount]);
17747
- React.useEffect(function () {
17748
- if (!formRef.current || isValidatedReference.current || isValid) return;
17749
- isValidatedReference.current = true;
17750
- var fieldErrorName = getErrorFieldName(errors);
17751
- if (!fieldErrorName) return;
17752
- var errorFormElement = formRef.current.querySelector("[name=\"".concat(fieldErrorName, "\"]"));
17753
- errorFormElement === null || errorFormElement === void 0 ? void 0 : errorFormElement.scrollIntoView({
17754
- behavior: "smooth",
17755
- block: "center"
17756
- });
17757
- }, [submitCount, errors]);
17758
17756
  return null;
17759
17757
  };
17760
17758
 
17761
17759
  var _excluded$j = ["values", "validateForm", "setErrors", "setTouched"];
17762
- var FormWrapper = /*#__PURE__*/React.forwardRef(function (_ref, formRef) {
17760
+ var FormWrapper = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
17763
17761
  var className = _ref.className,
17764
17762
  formProps = _ref.formProps,
17765
17763
  children = _ref.children,
@@ -17773,7 +17771,8 @@ var FormWrapper = /*#__PURE__*/React.forwardRef(function (_ref, formRef) {
17773
17771
  formikBag = _objectWithoutProperties$1(_useFormikContext, _excluded$j);
17774
17772
  var isFormDirty = formikBag.dirty,
17775
17773
  isSubmitting = formikBag.isSubmitting;
17776
- var formRefForScrollToErrorFiled = React.useRef();
17774
+ var formRefForScrollToErrorField = React.useRef();
17775
+ var formRef = ref || formRefForScrollToErrorField;
17777
17776
  var handleKeyDown = React.useCallback( /*#__PURE__*/function () {
17778
17777
  var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(event) {
17779
17778
  var isEventFromEditorOrTextarea, errors;
@@ -17814,6 +17813,7 @@ var FormWrapper = /*#__PURE__*/React.forwardRef(function (_ref, formRef) {
17814
17813
  if (Object.keys(errors).length > 0) {
17815
17814
  setErrors(errors);
17816
17815
  setTouched(errors);
17816
+ scrollToErrorField && scrollToError(formRef, errors);
17817
17817
  } else {
17818
17818
  onSubmit(values, formikBag);
17819
17819
  }
@@ -17838,10 +17838,10 @@ var FormWrapper = /*#__PURE__*/React.forwardRef(function (_ref, formRef) {
17838
17838
  noValidate: true,
17839
17839
  className: className,
17840
17840
  "data-testid": "neeto-ui-form-wrapper",
17841
- ref: formRef || formRefForScrollToErrorFiled,
17841
+ ref: formRef,
17842
17842
  onKeyDown: handleKeyDown
17843
17843
  }, formProps), scrollToErrorField && /*#__PURE__*/React__default["default"].createElement(ScrollToErrorField, {
17844
- formRef: formRef || formRefForScrollToErrorFiled
17844
+ formRef: formRef
17845
17845
  }), children);
17846
17846
  });
17847
17847
  FormWrapper.displayName = "FormWrapper";