@rjsf/core 5.18.4 → 5.18.6

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 (36) hide show
  1. package/dist/core.umd.js +101 -78
  2. package/dist/index.esm.js +101 -74
  3. package/dist/index.esm.js.map +3 -3
  4. package/dist/index.js +101 -74
  5. package/dist/index.js.map +3 -3
  6. package/lib/components/Form.d.ts +16 -2
  7. package/lib/components/Form.js +78 -57
  8. package/lib/components/Form.js.map +1 -1
  9. package/lib/components/fields/ArrayField.d.ts +2 -2
  10. package/lib/components/fields/NumberField.js +1 -1
  11. package/lib/components/fields/NumberField.js.map +1 -1
  12. package/lib/components/fields/ObjectField.js +5 -2
  13. package/lib/components/fields/ObjectField.js.map +1 -1
  14. package/lib/components/fields/SchemaField.js +4 -3
  15. package/lib/components/fields/SchemaField.js.map +1 -1
  16. package/lib/components/templates/BaseInputTemplate.js +2 -2
  17. package/lib/components/templates/BaseInputTemplate.js.map +1 -1
  18. package/lib/components/templates/WrapIfAdditionalTemplate.js +1 -1
  19. package/lib/components/templates/WrapIfAdditionalTemplate.js.map +1 -1
  20. package/lib/components/widgets/CheckboxesWidget.js +2 -2
  21. package/lib/components/widgets/CheckboxesWidget.js.map +1 -1
  22. package/lib/components/widgets/RadioWidget.js +2 -2
  23. package/lib/components/widgets/RadioWidget.js.map +1 -1
  24. package/lib/components/widgets/TextareaWidget.js +2 -2
  25. package/lib/components/widgets/TextareaWidget.js.map +1 -1
  26. package/lib/tsconfig.tsbuildinfo +1 -1
  27. package/package.json +6 -6
  28. package/src/components/Form.tsx +40 -21
  29. package/src/components/fields/NumberField.tsx +1 -1
  30. package/src/components/fields/ObjectField.tsx +6 -3
  31. package/src/components/fields/SchemaField.tsx +3 -3
  32. package/src/components/templates/BaseInputTemplate.tsx +5 -2
  33. package/src/components/templates/WrapIfAdditionalTemplate.tsx +1 -1
  34. package/src/components/widgets/CheckboxesWidget.tsx +4 -4
  35. package/src/components/widgets/RadioWidget.tsx +4 -4
  36. package/src/components/widgets/TextareaWidget.tsx +2 -2
@@ -202,13 +202,16 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
202
202
  const newFormData = { ...formData } as T;
203
203
 
204
204
  let type: RJSFSchema['type'] = undefined;
205
+ let defaultValue: RJSFSchema['default'] = undefined;
205
206
  if (isObject(schema.additionalProperties)) {
206
207
  type = schema.additionalProperties.type;
208
+ defaultValue = schema.additionalProperties.default;
207
209
  let apSchema = schema.additionalProperties;
208
210
  if (REF_KEY in apSchema) {
209
211
  const { schemaUtils } = registry;
210
212
  apSchema = schemaUtils.retrieveSchema({ $ref: apSchema[REF_KEY] } as S, formData);
211
213
  type = apSchema.type;
214
+ defaultValue = apSchema.default;
212
215
  }
213
216
  if (!type && (ANY_OF_KEY in apSchema || ONE_OF_KEY in apSchema)) {
214
217
  type = 'object';
@@ -217,7 +220,7 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
217
220
 
218
221
  const newKey = this.getAvailableKey('newKey', newFormData);
219
222
  // Cast this to make the `set` work properly
220
- set(newFormData as GenericObjectType, newKey, this.getDefaultValue(type));
223
+ set(newFormData as GenericObjectType, newKey, defaultValue ?? this.getDefaultValue(type));
221
224
 
222
225
  onChange(newFormData);
223
226
  };
@@ -233,8 +236,8 @@ class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
233
236
  idSchema,
234
237
  name,
235
238
  required = false,
236
- disabled = false,
237
- readonly = false,
239
+ disabled,
240
+ readonly,
238
241
  hideError,
239
242
  idPrefix,
240
243
  idSeparator,
@@ -150,12 +150,12 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
150
150
  );
151
151
 
152
152
  const FieldComponent = getFieldComponent<T, S, F>(schema, uiOptions, idSchema, registry);
153
- const disabled = Boolean(props.disabled || uiOptions.disabled);
154
- const readonly = Boolean(props.readonly || uiOptions.readonly || props.schema.readOnly || schema.readOnly);
153
+ const disabled = Boolean(uiOptions.disabled ?? props.disabled);
154
+ const readonly = Boolean(uiOptions.readonly ?? props.readonly ?? props.schema.readOnly ?? schema.readOnly);
155
155
  const uiSchemaHideError = uiOptions.hideError;
156
156
  // Set hideError to the value provided in the uiSchema, otherwise stick with the prop to propagate to children
157
157
  const hideError = uiSchemaHideError === undefined ? props.hideError : Boolean(uiSchemaHideError);
158
- const autofocus = Boolean(props.autofocus || uiOptions.autofocus);
158
+ const autofocus = Boolean(uiOptions.autofocus ?? props.autofocus);
159
159
  if (Object.keys(schema).length === 0) {
160
160
  return null;
161
161
  }
@@ -65,9 +65,12 @@ export default function BaseInputTemplate<
65
65
  ({ target: { value } }: ChangeEvent<HTMLInputElement>) => onChange(value === '' ? options.emptyValue : value),
66
66
  [onChange, options]
67
67
  );
68
- const _onBlur = useCallback(({ target: { value } }: FocusEvent<HTMLInputElement>) => onBlur(id, value), [onBlur, id]);
68
+ const _onBlur = useCallback(
69
+ ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.value),
70
+ [onBlur, id]
71
+ );
69
72
  const _onFocus = useCallback(
70
- ({ target: { value } }: FocusEvent<HTMLInputElement>) => onFocus(id, value),
73
+ ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.value),
71
74
  [onFocus, id]
72
75
  );
73
76
 
@@ -58,7 +58,7 @@ export default function WrapIfAdditionalTemplate<
58
58
  className='form-control'
59
59
  type='text'
60
60
  id={`${id}-key`}
61
- onBlur={(event) => onKeyChange(event.target.value)}
61
+ onBlur={({ target }) => onKeyChange(target && target.value)}
62
62
  defaultValue={label}
63
63
  />
64
64
  </div>
@@ -31,14 +31,14 @@ function CheckboxesWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
31
31
  const checkboxesValues = Array.isArray(value) ? value : [value];
32
32
 
33
33
  const handleBlur = useCallback(
34
- ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
35
- onBlur(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue)),
34
+ ({ target }: FocusEvent<HTMLInputElement>) =>
35
+ onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue)),
36
36
  [onBlur, id]
37
37
  );
38
38
 
39
39
  const handleFocus = useCallback(
40
- ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
41
- onFocus(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue)),
40
+ ({ target }: FocusEvent<HTMLInputElement>) =>
41
+ onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue)),
42
42
  [onFocus, id]
43
43
  );
44
44
  return (
@@ -30,14 +30,14 @@ function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
30
30
  const { enumOptions, enumDisabled, inline, emptyValue } = options;
31
31
 
32
32
  const handleBlur = useCallback(
33
- ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
34
- onBlur(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue)),
33
+ ({ target }: FocusEvent<HTMLInputElement>) =>
34
+ onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue)),
35
35
  [onBlur, id]
36
36
  );
37
37
 
38
38
  const handleFocus = useCallback(
39
- ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
40
- onFocus(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue)),
39
+ ({ target }: FocusEvent<HTMLInputElement>) =>
40
+ onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue)),
41
41
  [onFocus, id]
42
42
  );
43
43
 
@@ -24,12 +24,12 @@ function TextareaWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
24
24
  );
25
25
 
26
26
  const handleBlur = useCallback(
27
- ({ target: { value } }: FocusEvent<HTMLTextAreaElement>) => onBlur(id, value),
27
+ ({ target }: FocusEvent<HTMLTextAreaElement>) => onBlur(id, target && target.value),
28
28
  [onBlur, id]
29
29
  );
30
30
 
31
31
  const handleFocus = useCallback(
32
- ({ target: { value } }: FocusEvent<HTMLTextAreaElement>) => onFocus(id, value),
32
+ ({ target }: FocusEvent<HTMLTextAreaElement>) => onFocus(id, target && target.value),
33
33
  [id, onFocus]
34
34
  );
35
35