@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.js CHANGED
@@ -17706,6 +17706,15 @@ var getErrorFieldName = function getErrorFieldName(formikErrors) {
17706
17706
  var _transformObjectToDot;
17707
17707
  return (_transformObjectToDot = transformObjectToDotNotation(formikErrors)) === null || _transformObjectToDot === void 0 ? void 0 : _transformObjectToDot[0];
17708
17708
  };
17709
+ var scrollToError = function scrollToError(formRef, errors) {
17710
+ var fieldErrorName = getErrorFieldName(errors);
17711
+ if (!fieldErrorName) return;
17712
+ var errorFormElement = formRef.current.querySelector("[name=\"".concat(fieldErrorName, "\"]"));
17713
+ errorFormElement === null || errorFormElement === void 0 ? void 0 : errorFormElement.scrollIntoView({
17714
+ behavior: "smooth",
17715
+ block: "center"
17716
+ });
17717
+ };
17709
17718
 
17710
17719
  var ScrollToErrorField = function ScrollToErrorField(_ref) {
17711
17720
  var formRef = _ref.formRef;
@@ -17713,26 +17722,15 @@ var ScrollToErrorField = function ScrollToErrorField(_ref) {
17713
17722
  submitCount = _useFormikContext.submitCount,
17714
17723
  isValid = _useFormikContext.isValid,
17715
17724
  errors = _useFormikContext.errors;
17716
- var isValidatedReference = useRef(false);
17717
17725
  useEffect(function () {
17718
- isValidatedReference.current = false;
17726
+ if (!formRef.current || isValid) return;
17727
+ scrollToError(formRef, errors);
17719
17728
  }, [submitCount]);
17720
- useEffect(function () {
17721
- if (!formRef.current || isValidatedReference.current || isValid) return;
17722
- isValidatedReference.current = true;
17723
- var fieldErrorName = getErrorFieldName(errors);
17724
- if (!fieldErrorName) return;
17725
- var errorFormElement = formRef.current.querySelector("[name=\"".concat(fieldErrorName, "\"]"));
17726
- errorFormElement === null || errorFormElement === void 0 ? void 0 : errorFormElement.scrollIntoView({
17727
- behavior: "smooth",
17728
- block: "center"
17729
- });
17730
- }, [submitCount, errors]);
17731
17729
  return null;
17732
17730
  };
17733
17731
 
17734
17732
  var _excluded$j = ["values", "validateForm", "setErrors", "setTouched"];
17735
- var FormWrapper = /*#__PURE__*/forwardRef$1(function (_ref, formRef) {
17733
+ var FormWrapper = /*#__PURE__*/forwardRef$1(function (_ref, ref) {
17736
17734
  var className = _ref.className,
17737
17735
  formProps = _ref.formProps,
17738
17736
  children = _ref.children,
@@ -17746,7 +17744,8 @@ var FormWrapper = /*#__PURE__*/forwardRef$1(function (_ref, formRef) {
17746
17744
  formikBag = _objectWithoutProperties$1(_useFormikContext, _excluded$j);
17747
17745
  var isFormDirty = formikBag.dirty,
17748
17746
  isSubmitting = formikBag.isSubmitting;
17749
- var formRefForScrollToErrorFiled = useRef();
17747
+ var formRefForScrollToErrorField = useRef();
17748
+ var formRef = ref || formRefForScrollToErrorField;
17750
17749
  var handleKeyDown = useCallback( /*#__PURE__*/function () {
17751
17750
  var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(event) {
17752
17751
  var isEventFromEditorOrTextarea, errors;
@@ -17787,6 +17786,7 @@ var FormWrapper = /*#__PURE__*/forwardRef$1(function (_ref, formRef) {
17787
17786
  if (Object.keys(errors).length > 0) {
17788
17787
  setErrors(errors);
17789
17788
  setTouched(errors);
17789
+ scrollToErrorField && scrollToError(formRef, errors);
17790
17790
  } else {
17791
17791
  onSubmit(values, formikBag);
17792
17792
  }
@@ -17811,10 +17811,10 @@ var FormWrapper = /*#__PURE__*/forwardRef$1(function (_ref, formRef) {
17811
17811
  noValidate: true,
17812
17812
  className: className,
17813
17813
  "data-testid": "neeto-ui-form-wrapper",
17814
- ref: formRef || formRefForScrollToErrorFiled,
17814
+ ref: formRef,
17815
17815
  onKeyDown: handleKeyDown
17816
17816
  }, formProps), scrollToErrorField && /*#__PURE__*/React__default.createElement(ScrollToErrorField, {
17817
- formRef: formRef || formRefForScrollToErrorFiled
17817
+ formRef: formRef
17818
17818
  }), children);
17819
17819
  });
17820
17820
  FormWrapper.displayName = "FormWrapper";