@thecb/components 6.1.0-beta.3 → 6.1.0-beta.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "6.1.0-beta.3",
3
+ "version": "6.1.0-beta.4",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -1,14 +1,17 @@
1
1
  import { useEffect } from "react";
2
2
 
3
3
  const useFocusInvalidInput = (showErrors = false) => {
4
+ console.log("hey show errors", showErrors);
4
5
  // Only move focus when "showErrors" is true
5
6
  // "showErrors" is managed by container page of form
6
7
  // typically set to "true" on attempted form submission, if errors exist
7
8
  useEffect(() => {
9
+ console.log("inside use effect show errors", showErrors);
8
10
  if (showErrors) {
9
11
  const inputsWithErrors = document.querySelectorAll(
10
12
  "input[aria-invalid=true]"
11
13
  );
14
+ console.log("inputs with errors is", inputsWithErrors);
12
15
  inputsWithErrors?.[0]?.focus();
13
16
  }
14
17
  }, [showErrors]);
@@ -46,8 +46,18 @@ export const safeChildren = (children, replacement = []) => {
46
46
  return unsafeValues.includes(children) ? replacement : children;
47
47
  };
48
48
 
49
- export const generateClickHandler = (form, handleErrors, submitForm) => e => {
49
+ export const generateClickHandler = (
50
+ form,
51
+ handleErrors,
52
+ submitForm,
53
+ resetErrors
54
+ ) => e => {
50
55
  e.preventDefault();
56
+ if (resetErrors) {
57
+ // if provided, will reset error state tracker
58
+ // allows hooks that depend on error state to re-run
59
+ resetErrors();
60
+ }
51
61
  const formHasError = Object.values(form.fields).reduce(
52
62
  (acc, curr) => acc || curr.hasErrors,
53
63
  false