@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/dist/index.cjs.js +13 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +13 -2
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/util/focusFirstInvalidInputHook.js +3 -0
- package/src/util/general.js +11 -1
package/dist/index.cjs.js
CHANGED
|
@@ -6100,9 +6100,16 @@ var safeChildren = function safeChildren(children) {
|
|
|
6100
6100
|
|
|
6101
6101
|
return unsafeValues.includes(children) ? replacement : children;
|
|
6102
6102
|
};
|
|
6103
|
-
var generateClickHandler = function generateClickHandler(form, handleErrors, submitForm) {
|
|
6103
|
+
var generateClickHandler = function generateClickHandler(form, handleErrors, submitForm, resetErrors) {
|
|
6104
6104
|
return function (e) {
|
|
6105
6105
|
e.preventDefault();
|
|
6106
|
+
|
|
6107
|
+
if (resetErrors) {
|
|
6108
|
+
// if provided, will reset error state tracker
|
|
6109
|
+
// allows hooks that depend on error state to re-run
|
|
6110
|
+
resetErrors();
|
|
6111
|
+
}
|
|
6112
|
+
|
|
6106
6113
|
var formHasError = Object.values(form.fields).reduce(function (acc, curr) {
|
|
6107
6114
|
return acc || curr.hasErrors;
|
|
6108
6115
|
}, false);
|
|
@@ -43657,14 +43664,18 @@ var index$4 = /*#__PURE__*/Object.freeze({
|
|
|
43657
43664
|
|
|
43658
43665
|
var useFocusInvalidInput = function useFocusInvalidInput() {
|
|
43659
43666
|
var showErrors = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
43660
|
-
// Only move focus when "showErrors" is true
|
|
43667
|
+
console.log("hey show errors", showErrors); // Only move focus when "showErrors" is true
|
|
43661
43668
|
// "showErrors" is managed by container page of form
|
|
43662
43669
|
// typically set to "true" on attempted form submission, if errors exist
|
|
43670
|
+
|
|
43663
43671
|
React.useEffect(function () {
|
|
43672
|
+
console.log("inside use effect show errors", showErrors);
|
|
43673
|
+
|
|
43664
43674
|
if (showErrors) {
|
|
43665
43675
|
var _inputsWithErrors$;
|
|
43666
43676
|
|
|
43667
43677
|
var inputsWithErrors = document.querySelectorAll("input[aria-invalid=true]");
|
|
43678
|
+
console.log("inputs with errors is", inputsWithErrors);
|
|
43668
43679
|
inputsWithErrors === null || inputsWithErrors === void 0 ? void 0 : (_inputsWithErrors$ = inputsWithErrors[0]) === null || _inputsWithErrors$ === void 0 ? void 0 : _inputsWithErrors$.focus();
|
|
43669
43680
|
}
|
|
43670
43681
|
}, [showErrors]);
|