@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "6.0.9",
3
+ "version": "6.1.0-beta.3",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
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 };