@abgov/jsonforms-components 1.24.9 → 1.24.11

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
@@ -3459,8 +3459,7 @@ const GoATextControlTester = rankWith(1, isStringControl);
3459
3459
  const GoAInputTextControl = withJsonFormsControlProps(GoATextControl);
3460
3460
 
3461
3461
  const MultiLineText = props => {
3462
- var _a, _b, _c, _d, _e, _f, _g;
3463
- // eslint-disable-next-line
3462
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3464
3463
  const {
3465
3464
  data,
3466
3465
  config,
@@ -3472,35 +3471,69 @@ const MultiLineText = props => {
3472
3471
  schema,
3473
3472
  label
3474
3473
  } = props;
3474
+ const {
3475
+ required
3476
+ } = props;
3477
+ const [textAreaValue, _] = React.useState(data);
3475
3478
  const appliedUiSchemaOptions = Object.assign(Object.assign({}, config), uischema === null || uischema === void 0 ? void 0 : uischema.options);
3476
3479
  const placeholder = (appliedUiSchemaOptions === null || appliedUiSchemaOptions === void 0 ? void 0 : appliedUiSchemaOptions.placeholder) || (schema === null || schema === void 0 ? void 0 : schema.description) || '';
3477
3480
  const errorsFormInput = checkFieldValidity(props);
3478
3481
  const autoCapitalize = ((_b = (_a = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _a === void 0 ? void 0 : _a.componentProps) === null || _b === void 0 ? void 0 : _b.autoCapitalize) === true || ((_c = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _c === void 0 ? void 0 : _c.autoCapitalize) === true;
3479
3482
  const readOnly = (_f = (_e = (_d = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _d === void 0 ? void 0 : _d.componentProps) === null || _e === void 0 ? void 0 : _e.readOnly) !== null && _f !== void 0 ? _f : false;
3480
- return jsx(GoATextArea, Object.assign({
3483
+ const textAreaName = `${label || path}-text-area` || '';
3484
+ const textarea = (_g = document.getElementsByName(textAreaName)[0]) !== null && _g !== void 0 ? _g : null;
3485
+ useEffect(() => {
3486
+ if (textarea) {
3487
+ textarea.addEventListener('blur', onBlur);
3488
+ }
3489
+ return () => {
3490
+ if (textarea) {
3491
+ textarea.removeEventListener('blur', onBlur);
3492
+ }
3493
+ };
3494
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3495
+ }, [textarea]);
3496
+ const onBlur = event => {
3497
+ let eventTargetValue = '';
3498
+ if (event.target) {
3499
+ eventTargetValue = event.target.value;
3500
+ }
3501
+ onBlurForTextControl({
3502
+ name: path,
3503
+ controlProps: props,
3504
+ value: autoCapitalize ? eventTargetValue.toUpperCase() : eventTargetValue
3505
+ });
3506
+ };
3507
+ const txtAreaComponent = jsx(GoATextArea, Object.assign({
3481
3508
  error: errorsFormInput.length > 0,
3482
- value: data,
3509
+ value: textAreaValue,
3483
3510
  disabled: !enabled,
3484
3511
  readOnly: readOnly,
3485
3512
  placeholder: placeholder,
3486
3513
  testId: (appliedUiSchemaOptions === null || appliedUiSchemaOptions === void 0 ? void 0 : appliedUiSchemaOptions.testId) || `${id}-input`,
3487
- name: `${label || path}-text-area`,
3514
+ name: textAreaName,
3488
3515
  width: '100%',
3489
3516
  // Note: Paul Jan-09-2023. The latest ui-component come with the maxCount. We need to uncomment the following line when the component is updated
3490
3517
  // maxCount={schema.maxLength || 256}
3491
3518
  onKeyPress: (name, value, key) => {
3492
- onKeyPressForTextControl({
3493
- name,
3494
- value: autoCapitalize ? value.toUpperCase() : value,
3495
- key,
3496
- controlProps: props
3497
- });
3519
+ const newValue = autoCapitalize ? value.toUpperCase() : value;
3520
+ if (value.length === 0 || required && errorsFormInput.length === 0 && value.length > 0) {
3521
+ onKeyPressForTextControl({
3522
+ name,
3523
+ value: newValue,
3524
+ key,
3525
+ controlProps: props
3526
+ });
3527
+ }
3498
3528
  },
3499
- // Dont use handleChange in the onChange event, use the keyPress or onBlur.
3500
- // If you use it onChange along with keyPress event it will cause a
3501
- // side effect that causes the validation to render when it shouldnt.
3502
- onChange: (name, value) => {}
3503
- }, (_g = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _g === void 0 ? void 0 : _g.componentProps));
3529
+ onChange: (name, value) => {
3530
+ if (data !== value) {
3531
+ const newValue = autoCapitalize ? value.toUpperCase() : value;
3532
+ handleChange(path, newValue);
3533
+ }
3534
+ }
3535
+ }, (_h = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _h === void 0 ? void 0 : _h.componentProps));
3536
+ return txtAreaComponent;
3504
3537
  };
3505
3538
  const MultiLineTextControlInput = props => jsx(GoAInputBaseControl, Object.assign({}, props, {
3506
3539
  input: MultiLineText
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.24.9",
3
+ "version": "1.24.11",
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,8 +1,8 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { CellProps, WithClassname, ControlProps, RankedTester } from '@jsonforms/core';
3
3
  import { WithInputProps } from './type';
4
4
  export type GoAInputMultiLineTextProps = CellProps & WithClassname & WithInputProps;
5
5
  export declare const MultiLineText: (props: GoAInputMultiLineTextProps) => JSX.Element;
6
6
  export declare const MultiLineTextControlInput: (props: ControlProps) => import("react/jsx-runtime").JSX.Element;
7
7
  export declare const MultiLineTextControlTester: RankedTester;
8
- export declare const MultiLineTextControl: import("react").ComponentType<import("@jsonforms/core").OwnPropsOfControl>;
8
+ export declare const MultiLineTextControl: React.ComponentType<import("@jsonforms/core").OwnPropsOfControl>;