@abgov/jsonforms-components 1.2.0 → 1.2.1

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/index.esm.js CHANGED
@@ -2399,9 +2399,29 @@ const GoAInputBaseControl = props => {
2399
2399
  });
2400
2400
  };
2401
2401
 
2402
+ /**
2403
+ * Checks input controls data value to determine is required and has any data.
2404
+ * @param props - The JsonForm control props
2405
+ * @returns true if there is no data and is a required field
2406
+ */
2407
+ const isRequiredAndHasNoData = props => {
2408
+ const {
2409
+ data,
2410
+ required
2411
+ } = props;
2412
+ return required && (data === undefined || data.length === 0);
2413
+ };
2414
+ /**
2415
+ * Checks the key press value to determine if the key press is a 'Shift' or 'Tab'.
2416
+ * @param key - The key press value
2417
+ * @returns true if the key pressed is not a shift or tab key being pressed, otherwise false
2418
+ */
2419
+ const isNotKeyPressTabOrShift = key => {
2420
+ return !(key === 'Tab' || key === 'Shift') && key !== undefined;
2421
+ };
2422
+
2402
2423
  const GoAInputText = props => {
2403
2424
  var _a, _b, _c, _d;
2404
- // eslint-disable-next-line
2405
2425
  const {
2406
2426
  data,
2407
2427
  config,
@@ -2434,7 +2454,7 @@ const GoAInputText = props => {
2434
2454
  // side effect that causes the validation to render when it shouldnt.
2435
2455
  onChange: (name, value) => {},
2436
2456
  onKeyPress: (name, value, key) => {
2437
- if (!(key === 'Tab' || key === 'Shift')) {
2457
+ if (isNotKeyPressTabOrShift(key)) {
2438
2458
  if (autoCapitalize === true) {
2439
2459
  handleChange(path, value.toUpperCase());
2440
2460
  } else {
@@ -2443,10 +2463,12 @@ const GoAInputText = props => {
2443
2463
  }
2444
2464
  },
2445
2465
  onBlur: (name, value) => {
2446
- if (autoCapitalize === true) {
2447
- handleChange(path, value.toUpperCase());
2448
- } else {
2449
- handleChange(path, value);
2466
+ if (isRequiredAndHasNoData(props)) {
2467
+ if (autoCapitalize) {
2468
+ handleChange(path, value.toUpperCase());
2469
+ } else {
2470
+ handleChange(path, value);
2471
+ }
2450
2472
  }
2451
2473
  }
2452
2474
  }, (_d = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _d === void 0 ? void 0 : _d.componentProps));
@@ -2587,14 +2609,16 @@ const GoADateInput = props => {
2587
2609
  // side effect that causes the validation to render when it shouldn't.
2588
2610
  onChange: (name, value) => {},
2589
2611
  onKeyPress: (name, value, key) => {
2590
- if (!(key === 'Tab' || key === 'Shift')) {
2612
+ if (isNotKeyPressTabOrShift(key)) {
2591
2613
  value = standardizeDate(value) || '';
2592
2614
  handleChange(path, value);
2593
2615
  }
2594
2616
  },
2595
2617
  onBlur: (name, value) => {
2596
- value = standardizeDate(value) || '';
2597
- handleChange(path, value);
2618
+ if (isRequiredAndHasNoData(props)) {
2619
+ value = standardizeDate(value) || '';
2620
+ handleChange(path, value);
2621
+ }
2598
2622
  }
2599
2623
  }, reformatDateProps((_e = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _e === void 0 ? void 0 : _e.componentProps)));
2600
2624
  };
@@ -2640,7 +2664,7 @@ const GoANumberInput = props => {
2640
2664
  name: (appliedUiSchemaOptions === null || appliedUiSchemaOptions === void 0 ? void 0 : appliedUiSchemaOptions.name) || `${id || label}-input`,
2641
2665
  testId: (appliedUiSchemaOptions === null || appliedUiSchemaOptions === void 0 ? void 0 : appliedUiSchemaOptions.testId) || `${id}-input`,
2642
2666
  onKeyPress: (name, value, key) => {
2643
- if (!(key === 'Tab' || key === 'Shift')) {
2667
+ if (isNotKeyPressTabOrShift(key)) {
2644
2668
  let newValue = '';
2645
2669
  if (value !== '') {
2646
2670
  newValue = +value;
@@ -2649,11 +2673,13 @@ const GoANumberInput = props => {
2649
2673
  }
2650
2674
  },
2651
2675
  onBlur: (name, value) => {
2652
- let newValue = '';
2653
- if (value !== '') {
2654
- newValue = +value;
2676
+ if (isRequiredAndHasNoData(props)) {
2677
+ let newValue = '';
2678
+ if (value !== '') {
2679
+ newValue = +value;
2680
+ }
2681
+ handleChange(path, newValue);
2655
2682
  }
2656
- handleChange(path, newValue);
2657
2683
  },
2658
2684
  //Dont trigger the handleChange event on the onChange event as it will cause
2659
2685
  //issue with the error message from displaying, use keyPress or the onBlur event instead
@@ -2702,7 +2728,7 @@ const GoAInputInteger = props => {
2702
2728
  name: (appliedUiSchemaOptions === null || appliedUiSchemaOptions === void 0 ? void 0 : appliedUiSchemaOptions.name) || `${id || label}-input`,
2703
2729
  testId: (appliedUiSchemaOptions === null || appliedUiSchemaOptions === void 0 ? void 0 : appliedUiSchemaOptions.testId) || `${id}-input`,
2704
2730
  onKeyPress: (name, value, key) => {
2705
- if (!(key === 'Tab' || key === 'Shift')) {
2731
+ if (isNotKeyPressTabOrShift(key)) {
2706
2732
  let newValue = '';
2707
2733
  if (value !== '') {
2708
2734
  newValue = +value;
@@ -2711,11 +2737,13 @@ const GoAInputInteger = props => {
2711
2737
  }
2712
2738
  },
2713
2739
  onBlur: (name, value) => {
2714
- let newValue = '';
2715
- if (value !== '') {
2716
- newValue = +value;
2740
+ if (isRequiredAndHasNoData(props)) {
2741
+ let newValue = '';
2742
+ if (value !== '') {
2743
+ newValue = +value;
2744
+ }
2745
+ handleChange(path, newValue);
2717
2746
  }
2718
- handleChange(path, newValue);
2719
2747
  },
2720
2748
  //Dont trigger the handleChange event on the onChange event as it will cause
2721
2749
  //issue with the error message from displaying, use keyPress or the onBlur event instead
@@ -2758,14 +2786,16 @@ const GoADateTimeInput = props => {
2758
2786
  onChange: (name, value) => {},
2759
2787
  onKeyPress: (name, value, key) => {
2760
2788
  var _a;
2761
- if (!(key === 'Tab' || key === 'Shift')) {
2789
+ if (isNotKeyPressTabOrShift(key)) {
2762
2790
  value = isValidDate(value) ? (_a = new Date(value)) === null || _a === void 0 ? void 0 : _a.toISOString() : '';
2763
2791
  handleChange(path, value);
2764
2792
  }
2765
2793
  },
2766
2794
  onBlur: (name, value) => {
2767
- value = isValidDate(value) ? new Date(value).toISOString() : '';
2768
- handleChange(path, value);
2795
+ if (isRequiredAndHasNoData(props)) {
2796
+ value = isValidDate(value) ? new Date(value).toISOString() : '';
2797
+ handleChange(path, value);
2798
+ }
2769
2799
  }
2770
2800
  }, (_a = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _a === void 0 ? void 0 : _a.componentProps));
2771
2801
  };
@@ -2802,14 +2832,16 @@ const GoATimeInput = props => {
2802
2832
  disabled: !enabled,
2803
2833
  testId: (appliedUiSchemaOptions === null || appliedUiSchemaOptions === void 0 ? void 0 : appliedUiSchemaOptions.testId) || `${id}-input`,
2804
2834
  onBlur: (name, value) => {
2805
- handleChange(path, value);
2835
+ if (isRequiredAndHasNoData(props)) {
2836
+ handleChange(path, value);
2837
+ }
2806
2838
  },
2807
2839
  // Dont use handleChange in the onChange event, use the keyPress or onBlur.
2808
2840
  // If you use it onChange along with keyPress event it will cause a
2809
2841
  // side effect that causes the validation to render when it shouldnt.
2810
2842
  onChange: (name, value) => {},
2811
2843
  onKeyPress: (name, value, key) => {
2812
- if (!(key === 'Tab' || key === 'Shift')) {
2844
+ if (isNotKeyPressTabOrShift(key)) {
2813
2845
  handleChange(path, value);
2814
2846
  }
2815
2847
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Government of Alberta - React renderers for JSON Forms based on the design system.",
6
6
  "repository": "https://github.com/GovAlta/adsp-monorepo",
@@ -1,9 +1,8 @@
1
1
  import React from 'react';
2
2
  import { CellProps, WithClassname, ControlProps, RankedTester } from '@jsonforms/core';
3
3
  import { WithInputProps } from './type';
4
- type GoAInputDateTimeProps = CellProps & WithClassname & WithInputProps;
4
+ export type GoAInputDateTimeProps = CellProps & WithClassname & WithInputProps;
5
5
  export declare const GoADateTimeInput: (props: GoAInputDateTimeProps) => JSX.Element;
6
6
  export declare const GoADateTimeControl: (props: ControlProps) => import("react/jsx-runtime").JSX.Element;
7
7
  export declare const GoADateTimeControlTester: RankedTester;
8
8
  export declare const GoAInputDateTimeControl: React.ComponentType<import("@jsonforms/core").OwnPropsOfControl>;
9
- export {};
@@ -1,9 +1,8 @@
1
1
  import React from 'react';
2
2
  import { CellProps, WithClassname, ControlProps, RankedTester } from '@jsonforms/core';
3
3
  import { WithInputProps } from './type';
4
- type GoAInputIntegerProps = CellProps & WithClassname & WithInputProps;
4
+ export type GoAInputIntegerProps = CellProps & WithClassname & WithInputProps;
5
5
  export declare const GoAInputInteger: (props: GoAInputIntegerProps) => JSX.Element;
6
6
  export declare const GoAIntegerControl: (props: ControlProps) => import("react/jsx-runtime").JSX.Element;
7
7
  export declare const GoAIntegerControlTester: RankedTester;
8
8
  export declare const GoAInputIntegerControl: React.ComponentType<import("@jsonforms/core").OwnPropsOfControl>;
9
- export {};
@@ -1,9 +1,8 @@
1
1
  import React from 'react';
2
2
  import { CellProps, WithClassname, ControlProps, RankedTester } from '@jsonforms/core';
3
3
  import { WithInputProps } from './type';
4
- type GoAInputNumberProps = CellProps & WithClassname & WithInputProps;
4
+ export type GoAInputNumberProps = CellProps & WithClassname & WithInputProps;
5
5
  export declare const GoANumberInput: (props: GoAInputNumberProps) => JSX.Element;
6
6
  export declare const GoANumberControl: (props: ControlProps) => import("react/jsx-runtime").JSX.Element;
7
7
  export declare const GoANumberControlTester: RankedTester;
8
8
  export declare const GoAInputNumberControl: React.ComponentType<import("@jsonforms/core").OwnPropsOfControl>;
9
- export {};
@@ -1,9 +1,8 @@
1
1
  import React from 'react';
2
2
  import { CellProps, WithClassname, ControlProps, RankedTester } from '@jsonforms/core';
3
3
  import { WithInputProps } from './type';
4
- type GoAInputTextProps = CellProps & WithClassname & WithInputProps;
4
+ export type GoAInputTextProps = CellProps & WithClassname & WithInputProps;
5
5
  export declare const GoAInputText: (props: GoAInputTextProps) => JSX.Element;
6
6
  export declare const GoATextControl: (props: ControlProps) => import("react/jsx-runtime").JSX.Element;
7
7
  export declare const GoATextControlTester: RankedTester;
8
8
  export declare const GoAInputTextControl: React.ComponentType<import("@jsonforms/core").OwnPropsOfControl>;
9
- export {};
@@ -1,9 +1,8 @@
1
1
  import React from 'react';
2
2
  import { CellProps, WithClassname, ControlProps, RankedTester } from '@jsonforms/core';
3
3
  import { WithInputProps } from './type';
4
- type GoAInputTimeProps = CellProps & WithClassname & WithInputProps;
4
+ export type GoAInputTimeProps = CellProps & WithClassname & WithInputProps;
5
5
  export declare const GoATimeInput: (props: GoAInputTimeProps) => JSX.Element;
6
6
  export declare const GoATimeControl: (props: ControlProps) => import("react/jsx-runtime").JSX.Element;
7
7
  export declare const GoATimeControlTester: RankedTester;
8
8
  export declare const GoAInputTimeControl: React.ComponentType<import("@jsonforms/core").OwnPropsOfControl>;
9
- export {};
@@ -0,0 +1,13 @@
1
+ import { ControlProps } from '@jsonforms/core';
2
+ /**
3
+ * Checks input controls data value to determine is required and has any data.
4
+ * @param props - The JsonForm control props
5
+ * @returns true if there is no data and is a required field
6
+ */
7
+ export declare const isRequiredAndHasNoData: (props: ControlProps) => boolean | undefined;
8
+ /**
9
+ * Checks the key press value to determine if the key press is a 'Shift' or 'Tab'.
10
+ * @param key - The key press value
11
+ * @returns true if the key pressed is not a shift or tab key being pressed, otherwise false
12
+ */
13
+ export declare const isNotKeyPressTabOrShift: (key: string) => boolean;
@@ -19,7 +19,6 @@ export declare const controlScopeMatchesLabel: (scope: string, label: string) =>
19
19
  * @returns
20
20
  */
21
21
  export declare const getLabelText: (scope: string, label: string) => string;
22
- export declare const FIELD_REQUIRED = "data should pass \"isNotEmpty\" keyword validation";
23
22
  /**
24
23
  * Check if a required, defined input value is valid. Returns an appropriate
25
24
  * error message if not.