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

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