@evoke-platform/ui-components 1.0.0-dev.228 → 1.0.0-dev.230

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.
Files changed (18) hide show
  1. package/dist/published/components/custom/Form/FormComponents/DocumentComponent/DocumentComponent.d.ts +1 -0
  2. package/dist/published/components/custom/Form/FormComponents/DocumentComponent/DocumentComponent.js +3 -14
  3. package/dist/published/components/custom/Form/FormComponents/FormFieldComponent.d.ts +1 -0
  4. package/dist/published/components/custom/Form/FormComponents/FormFieldComponent.js +3 -14
  5. package/dist/published/components/custom/Form/FormComponents/ImageComponent/ImageComponent.d.ts +1 -0
  6. package/dist/published/components/custom/Form/FormComponents/ImageComponent/ImageComponent.js +12 -24
  7. package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectComponent.d.ts +1 -0
  8. package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectComponent.js +13 -25
  9. package/dist/published/components/custom/Form/FormComponents/UserComponent/UserComponent.d.ts +1 -0
  10. package/dist/published/components/custom/Form/FormComponents/UserComponent/UserComponent.js +15 -27
  11. package/dist/published/components/custom/Form/FormComponents/ViewOnlyComponent.d.ts +1 -0
  12. package/dist/published/components/custom/Form/FormComponents/ViewOnlyComponent.js +8 -6
  13. package/dist/published/components/custom/FormField/BooleanSelect/BooleanSelect.js +16 -3
  14. package/dist/published/components/custom/FormField/BooleanSelect/BooleanSelect.test.js +1 -2
  15. package/dist/published/components/custom/FormField/FormField.js +1 -1
  16. package/dist/published/components/custom/FormField/InputFieldComponent/InputFieldComponent.js +10 -8
  17. package/dist/published/components/custom/FormField/InputFieldComponent/InputFieldComponent.test.js +17 -0
  18. package/package.json +1 -1
@@ -20,4 +20,5 @@ export declare class DocumentComponent extends ReactComponent {
20
20
  handleValidation(value?: (File | SavedDocumentReference)[] | null): void;
21
21
  beforeSubmit(): Promise<void>;
22
22
  attachReact(element: Element): void;
23
+ detachReact(element: Element): void;
23
24
  }
@@ -28,20 +28,6 @@ export class DocumentComponent extends ReactComponent {
28
28
  this.handleChange = this.handleChange.bind(this);
29
29
  }
30
30
  init() {
31
- this.on('changed-' + this.component.conditional.when, (value) => {
32
- // set default value when conditional field is shown
33
- if (this.component.defaultValue && value === this.component.conditional.eq) {
34
- this.setValue(this.component.defaultValue);
35
- this.updateValue(this.component.defaultValue, { modified: true });
36
- }
37
- // clear data and errors when a true conditional field is hidden
38
- if (this.component.conditional.show && value !== this.component.conditional.eq) {
39
- this.setValue('');
40
- this.updateValue('', { modified: true });
41
- this.clearErrors();
42
- super.detach();
43
- }
44
- });
45
31
  this.on(`api-error`, (details) => {
46
32
  const error = details.find((detail) => detail.code === 'errorMessage' && detail.path.replace('/', '') === this.component.key);
47
33
  if (error) {
@@ -147,4 +133,7 @@ export class DocumentComponent extends ReactComponent {
147
133
  React.createElement(FormComponentWrapper, { ...this.component, inputId: inputId, viewOnly: !this.component.canUpdateProperty, errorMessage: this.errorMessages() },
148
134
  React.createElement(Document, { ...this.component, id: inputId, handleChange: this.handleChange, error: this.hasErrors(), value: this.dataValue }))), root);
149
135
  }
136
+ detachReact(element) {
137
+ ReactDOM.unmountComponentAtNode(element);
138
+ }
150
139
  }
@@ -38,5 +38,6 @@ export declare class FormFieldComponent extends ReactComponent {
38
38
  handleComponentChange: (components: any, value: any) => void;
39
39
  handleChange: (key: string, value: any) => void;
40
40
  attachReact(element: Element): void;
41
+ detachReact(element: Element): void;
41
42
  }
42
43
  export {};
@@ -145,20 +145,6 @@ export class FormFieldComponent extends ReactComponent {
145
145
  this.handleChange = this.handleChange.bind(this);
146
146
  }
147
147
  init() {
148
- this.on('changed-' + this.component.conditional.when, (value) => {
149
- //set default value when conditional field is shown
150
- if (this.component.defaultValue && value === this.component.conditional.eq) {
151
- this.setValue(this.component.defaultValue);
152
- this.updateValue(this.component.defaultValue, { modified: true });
153
- }
154
- //clear data and errors when a true conditional field is hidden
155
- if (value !== this.component.conditional.eq) {
156
- this.setValue('');
157
- this.updateValue('', { modified: true });
158
- this.clearErrors();
159
- super.detach();
160
- }
161
- });
162
148
  if (this.component.key.includes('.city') ||
163
149
  this.component.key.includes('.county') ||
164
150
  this.component.key.includes('.state') ||
@@ -481,4 +467,7 @@ export class FormFieldComponent extends ReactComponent {
481
467
  this.emit('changed-' + this.component.key, e.target.value);
482
468
  }, ...this.component, id: inputId, defaultValue: this.dataValue, mask: this.component.inputMask, error: this.hasErrors(), size: this.component.fieldHeight ?? 'medium' }))), root);
483
469
  }
470
+ detachReact(element) {
471
+ ReactDOM.unmountComponentAtNode(element);
472
+ }
484
473
  }
@@ -22,4 +22,5 @@ export declare class ImageComponent extends ReactComponent {
22
22
  handleChange: (key: string, value: string | null) => void;
23
23
  beforeSubmit(): void;
24
24
  attachReact(element: Element): void;
25
+ detachReact(element: Element): void;
25
26
  }
@@ -1,7 +1,7 @@
1
1
  import { ReactComponent } from '@formio/react';
2
2
  import { isEmpty } from 'lodash';
3
3
  import React from 'react';
4
- import { createRoot } from 'react-dom/client';
4
+ import ReactDOM from 'react-dom';
5
5
  import { FormComponentWrapper } from '../../Common';
6
6
  import { isPropertyVisible } from '../../utils';
7
7
  import { Image } from './Image';
@@ -27,25 +27,6 @@ export class ImageComponent extends ReactComponent {
27
27
  this.handleChange = this.handleChange.bind(this);
28
28
  }
29
29
  init() {
30
- this.on('changed-' + this.component.conditional.when, (value) => {
31
- //set default value when conditional field is shown
32
- if (this.component.defaultValue && value === this.component.conditional.eq) {
33
- this.setValue(this.component.defaultValue);
34
- this.updateValue(this.component.defaultValue, { modified: true });
35
- }
36
- //clear data and errors when a true conditional field is hidden
37
- if (this.component.conditional.show && value !== this.component.conditional.eq) {
38
- this.setValue('');
39
- this.updateValue('', { modified: true });
40
- this.clearErrors();
41
- super.detach();
42
- // Detach the componentRoot when the component is hidden
43
- if (this.componentRoot) {
44
- this.componentRoot.unmount();
45
- this.componentRoot = undefined;
46
- }
47
- }
48
- });
49
30
  if (this.component.initialValue && /^{{.*}}$/.test(this.component.initialValue)) {
50
31
  const regex = /^{{input\.(?<relatedObjectProperty>[a-zA-Z][a-zA-Z0-9_]*)\.(?<nestedProperty>[a-zA-Z][a-zA-Z0-9_]*)}}$/;
51
32
  const groups = regex.exec(this.component.initialValue)?.groups;
@@ -122,12 +103,19 @@ export class ImageComponent extends ReactComponent {
122
103
  this.element && this.attach(this.element);
123
104
  }
124
105
  attachReact(element) {
125
- if (!this.componentRoot) {
126
- this.componentRoot = createRoot(element);
106
+ let root = ReactDOM.findDOMNode(element);
107
+ if (!root) {
108
+ root = element;
127
109
  }
128
110
  // FormIO uses id for an enclosing div, so we need to give the input field a different id.
129
111
  const inputId = `${this.component.id}-input`;
130
- return this.componentRoot.render(React.createElement("div", null, !this.component.hidden ? (React.createElement(FormComponentWrapper, { ...this.component, inputId: inputId, viewOnly: !this.component.canUpdateProperty, errorMessage: this.errorMessages() },
131
- React.createElement(Image, { ...this.component, id: inputId, value: this.dataValue, handleChange: this.handleChange, error: this.hasErrors() }))) : null));
112
+ /* TODO: You'll see warnings to upgrade to React 18's createRoot();
113
+ * It'll cause issues with: field-level errors not showing up, conditional visibility not working, focus moving out of the form on keypress
114
+ * Will need to be revisited later. Possibly look into using this.ref */
115
+ return ReactDOM.render(React.createElement("div", null, !this.component.hidden ? (React.createElement(FormComponentWrapper, { ...this.component, inputId: inputId, viewOnly: !this.component.canUpdateProperty, errorMessage: this.errorMessages() },
116
+ React.createElement(Image, { ...this.component, id: inputId, value: this.dataValue, handleChange: this.handleChange, error: this.hasErrors() }))) : null), root);
117
+ }
118
+ detachReact(element) {
119
+ ReactDOM.unmountComponentAtNode(element);
132
120
  }
133
121
  }
@@ -31,5 +31,6 @@ export declare class ObjectComponent extends ReactComponent {
31
31
  handleChangeObjectProperty: (key: string, value?: ObjectInstance | null) => void;
32
32
  beforeSubmit(): void;
33
33
  attachReact(element: Element): void;
34
+ detachReact(element: Element): void;
34
35
  }
35
36
  export {};
@@ -2,7 +2,7 @@ import { ReactComponent } from '@formio/react';
2
2
  import dot from 'dot-object';
3
3
  import { cloneDeep, isEmpty, pick } from 'lodash';
4
4
  import React from 'react';
5
- import { createRoot } from 'react-dom/client';
5
+ import ReactDOM from 'react-dom';
6
6
  import { FormComponentWrapper } from '../../Common';
7
7
  import { getAllCriteriaInputs, getPrefixedUrl, isPropertyVisible, transformToWhere, updateCriteriaInputs, } from '../../utils';
8
8
  import { ObjectPropertyInput } from './ObjectPropertyInput';
@@ -33,25 +33,6 @@ export class ObjectComponent extends ReactComponent {
33
33
  this.handleChangeObjectProperty = this.handleChangeObjectProperty.bind(this);
34
34
  }
35
35
  init() {
36
- this.on('changed-' + this.component.conditional.when, (value) => {
37
- //set default value when conditional field is shown
38
- if (this.component.defaultValue && value === this.component.conditional.eq) {
39
- this.setValue(this.component.defaultValue);
40
- this.updateValue(this.component.defaultValue, { modified: true });
41
- }
42
- //clear data and errors when a true conditional field is hidden
43
- if (this.component.conditional.show && value !== this.component.conditional.eq) {
44
- this.setValue('');
45
- this.updateValue('', { modified: true });
46
- this.clearErrors();
47
- super.detach();
48
- // Detach the componentRoot when the component is hidden
49
- if (this.componentRoot) {
50
- this.componentRoot.unmount();
51
- this.componentRoot = undefined;
52
- }
53
- }
54
- });
55
36
  const data = dot.dot(this.root._data);
56
37
  if (this.criteria) {
57
38
  const inputProps = getAllCriteriaInputs(this.criteria);
@@ -182,6 +163,10 @@ export class ObjectComponent extends ReactComponent {
182
163
  this.element && this.attach(this.element);
183
164
  }
184
165
  attachReact(element) {
166
+ let root = ReactDOM.findDOMNode(element);
167
+ if (!root) {
168
+ root = element;
169
+ }
185
170
  const updatedComponent = {
186
171
  ...this.component,
187
172
  instance: {
@@ -190,13 +175,16 @@ export class ObjectComponent extends ReactComponent {
190
175
  },
191
176
  defaultValueCriteria: this.updatedDefaultValueCriteria,
192
177
  };
193
- if (!this.componentRoot) {
194
- this.componentRoot = createRoot(element);
195
- }
196
178
  // FormIO uses id for an enclosing div, so we need to give the input field a different id.
197
179
  const inputId = `${this.component.id}-input`;
198
- return this.componentRoot.render(React.createElement("div", null,
180
+ /* TODO: You'll see warnings to upgrade to React 18's createRoot();
181
+ * It'll cause issues with: field-level errors not showing up, conditional visibility not working, focus moving out of the form on keypress
182
+ * Will need to be revisited later. Possibly look into using this.ref */
183
+ return ReactDOM.render(React.createElement("div", null,
199
184
  React.createElement(FormComponentWrapper, { ...updatedComponent, inputId: inputId, errorMessage: this.errorMessages() },
200
- React.createElement(ObjectPropertyInput, { ...updatedComponent, id: inputId, handleChangeObjectProperty: this.handleChangeObjectProperty, error: this.hasErrors(), filter: this.criteria ? { where: transformToWhere(this.updatedCriteria) } : undefined }))));
185
+ React.createElement(ObjectPropertyInput, { ...updatedComponent, id: inputId, handleChangeObjectProperty: this.handleChangeObjectProperty, error: this.hasErrors(), filter: this.criteria ? { where: transformToWhere(this.updatedCriteria) } : undefined }))), root);
186
+ }
187
+ detachReact(element) {
188
+ ReactDOM.unmountComponentAtNode(element);
201
189
  }
202
190
  }
@@ -25,4 +25,5 @@ export declare class UserComponent extends ReactComponent {
25
25
  handleChangeUserProperty: (value: AutocompleteOption) => void;
26
26
  beforeSubmit(): void;
27
27
  attachReact(element: Element): void;
28
+ detachReact(element: Element): void;
28
29
  }
@@ -1,9 +1,9 @@
1
1
  import { ReactComponent } from '@formio/react';
2
2
  import { cloneDeep, isEmpty } from 'lodash';
3
3
  import React from 'react';
4
- import { createRoot } from 'react-dom/client';
4
+ import ReactDOM from 'react-dom';
5
5
  import { FormComponentWrapper } from '../../Common';
6
- import { isPropertyVisible, transformToWhere } from '../../utils';
6
+ import { transformToWhere } from '../../utils';
7
7
  import { UserProperty } from './UserProperty';
8
8
  export class UserComponent extends ReactComponent {
9
9
  constructor(component, options, data) {
@@ -29,25 +29,6 @@ export class UserComponent extends ReactComponent {
29
29
  this.handleChangeUserProperty = this.handleChangeUserProperty.bind(this);
30
30
  }
31
31
  init() {
32
- this.on('changed-' + this.component.conditional.when, (value) => {
33
- // set default value when conditional field is shown
34
- if (this.component.defaultValue && value === this.component.conditional.eq) {
35
- this.setValue(this.component.defaultValue);
36
- this.updateValue(this.component.defaultValue, { modified: true });
37
- }
38
- // clear data and errors when a true conditional field is hidden
39
- if (this.component.conditional.show && value !== this.component.conditional.eq) {
40
- this.setValue('');
41
- this.updateValue('', { modified: true });
42
- this.clearErrors();
43
- super.detach();
44
- // Detach the componentRoot when the component is hidden
45
- if (this.componentRoot) {
46
- this.componentRoot.unmount();
47
- this.componentRoot = undefined;
48
- }
49
- }
50
- });
51
32
  if (this.component.initialValue && /^{{.*}}$/.test(this.component.initialValue)) {
52
33
  const regex = /^{{input\.(?<relatedObjectProperty>[a-zA-Z][a-zA-Z0-9_]*)\.(?<nestedProperty>[a-zA-Z][a-zA-Z0-9_]*)}}$/;
53
34
  const groups = regex.exec(this.component.initialValue)?.groups;
@@ -90,7 +71,7 @@ export class UserComponent extends ReactComponent {
90
71
  this.root.customErrors = this.root.customErrors.filter((error) => error.formattedKeyOrPath !== this.component.key);
91
72
  }
92
73
  handleValidation() {
93
- if (!isPropertyVisible(this.component.conditional, this.root.data)) {
74
+ if (!this.visible) {
94
75
  return;
95
76
  }
96
77
  // check for out-of-the-box formio errors which store on this.root.errors
@@ -123,6 +104,10 @@ export class UserComponent extends ReactComponent {
123
104
  this.element && this.attach(this.element);
124
105
  }
125
106
  attachReact(element) {
107
+ let root = ReactDOM.findDOMNode(element);
108
+ if (!root) {
109
+ root = element;
110
+ }
126
111
  const updatedComponent = {
127
112
  ...this.component,
128
113
  instance: {
@@ -130,13 +115,16 @@ export class UserComponent extends ReactComponent {
130
115
  [this.component.key]: isEmpty(this.dataValue) ? null : this.dataValue,
131
116
  },
132
117
  };
133
- if (!this.componentRoot) {
134
- this.componentRoot = createRoot(element, { onRecoverableError: console.error });
135
- }
136
118
  // FormIO uses id for an enclosing div, so we need to give the input field a different id.
137
119
  const inputId = `${this.component.id}-input`;
138
- return this.componentRoot.render(React.createElement("div", null,
120
+ /* TODO: You'll see warnings to upgrade to React 18's createRoot();
121
+ * It'll cause issues with: field-level errors not showing up, conditional visibility not working, focus moving out of the form on keypress
122
+ * Will need to be revisited later. Possibly look into using this.ref */
123
+ return ReactDOM.render(React.createElement("div", null,
139
124
  React.createElement(FormComponentWrapper, { ...updatedComponent, inputId: inputId, errorMessage: this.errorMessages() },
140
- React.createElement(UserProperty, { ...updatedComponent, id: inputId, value: this.dataValue ?? '', handleChangeUserProperty: this.handleChangeUserProperty, error: this.hasErrors(), filter: this.criteria ? { where: transformToWhere(this.updatedCriteria) } : undefined }))));
125
+ React.createElement(UserProperty, { ...updatedComponent, id: inputId, value: this.dataValue ?? '', handleChangeUserProperty: this.handleChangeUserProperty, error: this.hasErrors(), filter: this.criteria ? { where: transformToWhere(this.updatedCriteria) } : undefined }))), root);
126
+ }
127
+ detachReact(element) {
128
+ ReactDOM.unmountComponentAtNode(element);
141
129
  }
142
130
  }
@@ -17,4 +17,5 @@ export declare class ViewOnlyComponent extends ReactComponent {
17
17
  constructor(component: BaseFormComponentProps, options: any, data: any);
18
18
  showValue(value: unknown): {} | undefined;
19
19
  attachReact(element: Element): void;
20
+ detachReact(element: Element): void;
20
21
  }
@@ -3,7 +3,6 @@ import { get, isEmpty } from 'lodash';
3
3
  import { DateTime } from 'luxon';
4
4
  import React from 'react';
5
5
  import ReactDOM from 'react-dom';
6
- import { createRoot } from 'react-dom/client';
7
6
  import { Link, Typography } from '../../../core';
8
7
  import { FormComponentWrapper } from '../Common/FormComponentWrapper';
9
8
  export class ViewOnlyComponent extends ReactComponent {
@@ -74,13 +73,16 @@ export class ViewOnlyComponent extends ReactComponent {
74
73
  if (!root) {
75
74
  root = element;
76
75
  }
77
- if (!this.componentRoot) {
78
- this.componentRoot = createRoot(root);
79
- }
80
- return this.componentRoot.render(React.createElement("div", null,
76
+ /* TODO: You'll see warnings to upgrade to React 18's createRoot();
77
+ * It'll cause issues with: field-level errors not showing up, conditional visibility not working, focus moving out of the form on keypress
78
+ * Will need to be revisited later. Possibly look into using this.ref */
79
+ return ReactDOM.render(React.createElement("div", null,
81
80
  React.createElement(FormComponentWrapper, { ...this.component, viewOnly: true },
82
81
  React.createElement(Typography, { variant: "body1", key: this.component.key }, this.showValue(this.component.instance
83
82
  ? get(this.component.instance, this.component.key)
84
- : this.component.defaultValue)))));
83
+ : this.component.defaultValue)))), root);
84
+ }
85
+ detachReact(element) {
86
+ ReactDOM.unmountComponentAtNode(element);
85
87
  }
86
88
  }
@@ -8,8 +8,8 @@ const BooleanSelect = (props) => {
8
8
  setValue(defaultValue);
9
9
  }, [defaultValue]);
10
10
  const handleChange = (event, selected) => {
11
- setValue(selected.label);
12
- props.onChange(property.id, selected.label, property);
11
+ setValue(selected.value);
12
+ props.onChange(property.id, selected.value, property);
13
13
  };
14
14
  const booleanOptions = [
15
15
  {
@@ -21,6 +21,19 @@ const BooleanSelect = (props) => {
21
21
  value: false,
22
22
  },
23
23
  ];
24
- return readOnly ? (React.createElement(InputFieldComponent, { ...props })) : (React.createElement(Autocomplete, { id: id, renderInput: (params) => (React.createElement(TextField, { ...params, value: value, error: error, errorMessage: errorMessage, onBlur: onBlur, fullWidth: true, sx: { background: 'white' }, size: size ?? 'medium', placeholder: placeholder })), value: value, onChange: handleChange, inputValue: value, options: booleanOptions, disableClearable: true, sx: { background: 'white', borderRadius: '8px' }, ...(additionalProps ?? {}) }));
24
+ return readOnly ? (React.createElement(InputFieldComponent, { ...props })) : (React.createElement(Autocomplete, { id: id, renderInput: (params) => (React.createElement(TextField, { ...params, error: error, errorMessage: errorMessage, onBlur: onBlur, fullWidth: true, sx: { background: 'white' }, size: size ?? 'medium', placeholder: placeholder })), value: value, onChange: handleChange, isOptionEqualToValue: (option, val) => {
25
+ if (typeof val === 'boolean') {
26
+ return option.value === val;
27
+ }
28
+ return option.value === val?.value;
29
+ }, getOptionLabel: (option) => {
30
+ if (typeof option === 'boolean') {
31
+ const opt = booleanOptions.find((o) => o.value === option);
32
+ return opt ? opt.label : option;
33
+ }
34
+ if (typeof option === 'string')
35
+ return option;
36
+ return option.label;
37
+ }, options: booleanOptions, disableClearable: true, sx: { background: 'white', borderRadius: '8px' }, ...(additionalProps ?? {}) }));
25
38
  };
26
39
  export default BooleanSelect;
@@ -18,6 +18,5 @@ test('returns selected option', async () => {
18
18
  await user.click(inputField);
19
19
  const yesOption = await screen.findByRole('option', { name: 'Yes' });
20
20
  await user.click(yesOption);
21
- expect(onChangeMock).toBeCalledWith('theQuestion', 'Yes', // ?? why not true/false?
22
- booleanProperty);
21
+ expect(onChangeMock).toBeCalledWith('theQuestion', true, booleanProperty);
23
22
  });
@@ -37,7 +37,7 @@ const FormField = (props) => {
37
37
  }
38
38
  switch (property.type) {
39
39
  case 'boolean':
40
- control = (React.createElement(BooleanSelect, { ...commonProps, defaultValue: defaultValue ? 'Yes' : defaultValue === undefined ? '' : 'No' }));
40
+ control = React.createElement(BooleanSelect, { ...commonProps, defaultValue: defaultValue });
41
41
  break;
42
42
  case 'date':
43
43
  control = React.createElement(DatePickerSelect, { ...commonProps });
@@ -1,3 +1,4 @@
1
+ import { isEmpty } from 'lodash';
1
2
  import React, { useEffect, useState } from 'react';
2
3
  import InputMask from 'react-input-mask';
3
4
  import NumberFormat from 'react-number-format';
@@ -39,14 +40,15 @@ const InputFieldComponent = (props) => {
39
40
  : property.type === 'integer'
40
41
  ? { inputProps: { min, max } }
41
42
  : null;
42
- const selectOptions = property.enum ?? [];
43
- if (property.enum && !property.enum.includes(value)) {
44
- //note: this is different between widgets and builder
45
- //builder had select options being {label, value}
46
- //widgets had it like this, as strings w/isOptionEqualToValue
47
- selectOptions.push(value);
48
- }
49
- return property.enum && !readOnly ? (React.createElement(Autocomplete, { id: id, options: selectOptions, onChange: handleSelectChange, renderInput: (params) => (React.createElement(TextField, { ...params, value: value, error: error, errorMessage: errorMessage, fullWidth: true, onBlur: onBlur, size: size ?? 'medium', placeholder: placeholder })), disableClearable: true, value: value, isOptionEqualToValue: (option, value) => {
43
+ return property.enum && !readOnly ? (React.createElement(Autocomplete, { id: id,
44
+ // note: this is different between widgets and builder
45
+ // builder had select options being {label, value}
46
+ // widgets had it like this, as strings w/isOptionEqualToValue
47
+ options: typeof defaultValue === 'string' &&
48
+ !isEmpty(defaultValue) &&
49
+ !property.enum.find((val) => val === defaultValue)
50
+ ? [...property.enum, defaultValue]
51
+ : property.enum, onChange: handleSelectChange, renderInput: (params) => (React.createElement(TextField, { ...params, value: value, error: error, errorMessage: errorMessage, fullWidth: true, onBlur: onBlur, size: size ?? 'medium', placeholder: placeholder })), disableClearable: true, value: value, isOptionEqualToValue: (option, value) => {
50
52
  return option.value === value;
51
53
  }, error: error, required: required, inputValue: inputValue ?? '', onInputChange: handleInputValueChange, ...(additionalProps ?? {}) })) : !mask ? (React.createElement(TextField, { id: id, sx: {
52
54
  background: 'white',
@@ -40,4 +40,21 @@ describe('Autocomplete', () => {
40
40
  await user.click(option2);
41
41
  expect(onChangeMock).toBeCalledWith('enumField', 'option 2', enumProperty);
42
42
  });
43
+ test('does not include blank default value in options', async () => {
44
+ const user = userEvent.setup();
45
+ const onChangeMock = jest.fn((name, value, property) => { });
46
+ render(React.createElement(InputField, { id: "testInput", property: enumProperty, onChange: onChangeMock, defaultValue: null }));
47
+ const input = screen.getByRole('combobox');
48
+ await user.click(input);
49
+ const blankOption = screen.queryByRole('option', { name: '' });
50
+ expect(blankOption).not.toBeInTheDocument();
51
+ });
52
+ test('includes default value in options', async () => {
53
+ const user = userEvent.setup();
54
+ const onChangeMock = jest.fn((name, value, property) => { });
55
+ render(React.createElement(InputField, { id: "testInput", property: enumProperty, onChange: onChangeMock, defaultValue: 'Default' }));
56
+ const input = screen.getByRole('combobox');
57
+ await user.click(input);
58
+ await screen.findByRole('option', { name: 'Default' });
59
+ });
43
60
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.0.0-dev.228",
3
+ "version": "1.0.0-dev.230",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",