@thecb/components 6.0.9 → 6.1.0-beta.3
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 +19 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +19 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/.DS_Store +0 -0
- package/src/components/atoms/form-layouts/FormInput.js +8 -0
- package/src/util/focusFirstInvalidInputHook.js +17 -0
- package/src/util/index.js +2 -1
package/package.json
CHANGED
package/src/.DS_Store
ADDED
|
Binary file
|
|
@@ -194,6 +194,10 @@ const FormInput = ({
|
|
|
194
194
|
labelTextWhenNoError,
|
|
195
195
|
"error message"
|
|
196
196
|
)}
|
|
197
|
+
aria-invalid={
|
|
198
|
+
(field.dirty && field.hasErrors) ||
|
|
199
|
+
(field.hasErrors && showErrors)
|
|
200
|
+
}
|
|
197
201
|
onChange={e => fieldActions.set(e)}
|
|
198
202
|
type={type}
|
|
199
203
|
value={field.rawValue}
|
|
@@ -215,6 +219,10 @@ const FormInput = ({
|
|
|
215
219
|
labelTextWhenNoError,
|
|
216
220
|
"error message"
|
|
217
221
|
)}
|
|
222
|
+
aria-invalid={
|
|
223
|
+
(field.dirty && field.hasErrors) ||
|
|
224
|
+
(field.hasErrors && showErrors)
|
|
225
|
+
}
|
|
218
226
|
onChange={e => fieldActions.set(e.target.value)}
|
|
219
227
|
type={type === "password" && showPassword ? "text" : type}
|
|
220
228
|
value={field.rawValue}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
const useFocusInvalidInput = (showErrors = false) => {
|
|
4
|
+
// Only move focus when "showErrors" is true
|
|
5
|
+
// "showErrors" is managed by container page of form
|
|
6
|
+
// typically set to "true" on attempted form submission, if errors exist
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (showErrors) {
|
|
9
|
+
const inputsWithErrors = document.querySelectorAll(
|
|
10
|
+
"input[aria-invalid=true]"
|
|
11
|
+
);
|
|
12
|
+
inputsWithErrors?.[0]?.focus();
|
|
13
|
+
}
|
|
14
|
+
}, [showErrors]);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default useFocusInvalidInput;
|
package/src/util/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as formats from "./formats";
|
|
2
2
|
import * as general from "./general";
|
|
3
3
|
import * as theme from "./themeUtils";
|
|
4
|
+
import useFocusInvalidInput from "./focusFirstInvalidInputHook";
|
|
4
5
|
|
|
5
|
-
export { formats, general, theme };
|
|
6
|
+
export { formats, general, theme, useFocusInvalidInput };
|