@rjsf/core 6.6.1 → 6.7.0

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 (262) hide show
  1. package/LICENSE.md +201 -0
  2. package/dist/core.umd.js +694 -584
  3. package/dist/index.cjs +1191 -1071
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.esm.js +1030 -984
  6. package/dist/index.esm.js.map +4 -4
  7. package/lib/components/Form.d.ts +16 -13
  8. package/lib/components/Form.d.ts.map +1 -1
  9. package/lib/components/Form.js +126 -76
  10. package/lib/components/RichDescription.d.ts +3 -3
  11. package/lib/components/RichDescription.d.ts.map +1 -1
  12. package/lib/components/RichDescription.js +1 -1
  13. package/lib/components/RichHelp.d.ts +3 -3
  14. package/lib/components/RichHelp.d.ts.map +1 -1
  15. package/lib/components/RichHelp.js +1 -1
  16. package/lib/components/SchemaExamples.d.ts +2 -2
  17. package/lib/components/SchemaExamples.d.ts.map +1 -1
  18. package/lib/components/SchemaExamples.js +1 -3
  19. package/lib/components/fields/ArrayField.d.ts +2 -2
  20. package/lib/components/fields/ArrayField.d.ts.map +1 -1
  21. package/lib/components/fields/ArrayField.js +87 -88
  22. package/lib/components/fields/BooleanField.d.ts +2 -2
  23. package/lib/components/fields/BooleanField.d.ts.map +1 -1
  24. package/lib/components/fields/BooleanField.js +2 -5
  25. package/lib/components/fields/CyclicSchemaField.d.ts +8 -0
  26. package/lib/components/fields/CyclicSchemaField.d.ts.map +1 -0
  27. package/lib/components/fields/CyclicSchemaField.js +21 -0
  28. package/lib/components/fields/FallbackField.d.ts +2 -2
  29. package/lib/components/fields/FallbackField.d.ts.map +1 -1
  30. package/lib/components/fields/FallbackField.js +2 -2
  31. package/lib/components/fields/LayoutGridField.d.ts +8 -10
  32. package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
  33. package/lib/components/fields/LayoutGridField.js +5 -4
  34. package/lib/components/fields/LayoutHeaderField.d.ts +2 -2
  35. package/lib/components/fields/LayoutHeaderField.d.ts.map +1 -1
  36. package/lib/components/fields/LayoutHeaderField.js +1 -1
  37. package/lib/components/fields/LayoutMultiSchemaField.d.ts +2 -2
  38. package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -1
  39. package/lib/components/fields/LayoutMultiSchemaField.js +4 -1
  40. package/lib/components/fields/MultiSchemaField.d.ts +2 -41
  41. package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
  42. package/lib/components/fields/MultiSchemaField.js +116 -122
  43. package/lib/components/fields/NullField.d.ts +1 -1
  44. package/lib/components/fields/NullField.d.ts.map +1 -1
  45. package/lib/components/fields/NumberField.d.ts +2 -2
  46. package/lib/components/fields/NumberField.d.ts.map +1 -1
  47. package/lib/components/fields/NumberField.js +7 -9
  48. package/lib/components/fields/ObjectField.d.ts +2 -2
  49. package/lib/components/fields/ObjectField.d.ts.map +1 -1
  50. package/lib/components/fields/ObjectField.js +28 -26
  51. package/lib/components/fields/OptionalDataControlsField.d.ts +2 -2
  52. package/lib/components/fields/OptionalDataControlsField.d.ts.map +1 -1
  53. package/lib/components/fields/SchemaField.d.ts +14 -8
  54. package/lib/components/fields/SchemaField.d.ts.map +1 -1
  55. package/lib/components/fields/SchemaField.js +43 -30
  56. package/lib/components/fields/StringField.d.ts +2 -2
  57. package/lib/components/fields/StringField.d.ts.map +1 -1
  58. package/lib/components/fields/StringField.js +2 -5
  59. package/lib/components/fields/index.d.ts +1 -1
  60. package/lib/components/fields/index.d.ts.map +1 -1
  61. package/lib/components/fields/index.js +2 -0
  62. package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +2 -2
  63. package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts.map +1 -1
  64. package/lib/components/templates/ArrayFieldDescriptionTemplate.js +1 -1
  65. package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +2 -2
  66. package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -1
  67. package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +1 -1
  68. package/lib/components/templates/ArrayFieldItemTemplate.d.ts +2 -2
  69. package/lib/components/templates/ArrayFieldItemTemplate.d.ts.map +1 -1
  70. package/lib/components/templates/ArrayFieldItemTemplate.js +1 -1
  71. package/lib/components/templates/ArrayFieldTemplate.d.ts +2 -2
  72. package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
  73. package/lib/components/templates/ArrayFieldTemplate.js +1 -1
  74. package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +2 -2
  75. package/lib/components/templates/ArrayFieldTitleTemplate.d.ts.map +1 -1
  76. package/lib/components/templates/ArrayFieldTitleTemplate.js +1 -1
  77. package/lib/components/templates/BaseInputTemplate.d.ts +2 -2
  78. package/lib/components/templates/BaseInputTemplate.d.ts.map +1 -1
  79. package/lib/components/templates/BaseInputTemplate.js +7 -6
  80. package/lib/components/templates/ButtonTemplates/AddButton.d.ts +2 -2
  81. package/lib/components/templates/ButtonTemplates/AddButton.d.ts.map +1 -1
  82. package/lib/components/templates/ButtonTemplates/IconButton.d.ts +14 -7
  83. package/lib/components/templates/ButtonTemplates/IconButton.d.ts.map +1 -1
  84. package/lib/components/templates/ButtonTemplates/IconButton.js +14 -6
  85. package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts +2 -2
  86. package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts.map +1 -1
  87. package/lib/components/templates/ButtonTemplates/index.d.ts +1 -1
  88. package/lib/components/templates/ButtonTemplates/index.d.ts.map +1 -1
  89. package/lib/components/templates/CyclicSchemaExpandTemplate.d.ts +7 -0
  90. package/lib/components/templates/CyclicSchemaExpandTemplate.d.ts.map +1 -0
  91. package/lib/components/templates/CyclicSchemaExpandTemplate.js +12 -0
  92. package/lib/components/templates/DescriptionField.d.ts +2 -2
  93. package/lib/components/templates/DescriptionField.d.ts.map +1 -1
  94. package/lib/components/templates/ErrorList.d.ts +2 -2
  95. package/lib/components/templates/ErrorList.d.ts.map +1 -1
  96. package/lib/components/templates/ErrorList.js +2 -4
  97. package/lib/components/templates/FallbackFieldTemplate.d.ts +2 -2
  98. package/lib/components/templates/FallbackFieldTemplate.d.ts.map +1 -1
  99. package/lib/components/templates/FieldErrorTemplate.d.ts +2 -2
  100. package/lib/components/templates/FieldErrorTemplate.d.ts.map +1 -1
  101. package/lib/components/templates/FieldErrorTemplate.js +1 -3
  102. package/lib/components/templates/FieldHelpTemplate.d.ts +2 -2
  103. package/lib/components/templates/FieldHelpTemplate.d.ts.map +1 -1
  104. package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts +2 -2
  105. package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts.map +1 -1
  106. package/lib/components/templates/FieldTemplate/FieldTemplate.js +1 -1
  107. package/lib/components/templates/FieldTemplate/Label.d.ts +3 -3
  108. package/lib/components/templates/FieldTemplate/Label.d.ts.map +1 -1
  109. package/lib/components/templates/GridTemplate.d.ts +2 -2
  110. package/lib/components/templates/GridTemplate.d.ts.map +1 -1
  111. package/lib/components/templates/MultiSchemaFieldTemplate.d.ts +2 -2
  112. package/lib/components/templates/MultiSchemaFieldTemplate.d.ts.map +1 -1
  113. package/lib/components/templates/ObjectFieldTemplate.d.ts +2 -2
  114. package/lib/components/templates/ObjectFieldTemplate.d.ts.map +1 -1
  115. package/lib/components/templates/ObjectFieldTemplate.js +1 -1
  116. package/lib/components/templates/OptionalDataControlsTemplate.d.ts +2 -2
  117. package/lib/components/templates/OptionalDataControlsTemplate.d.ts.map +1 -1
  118. package/lib/components/templates/OptionalDataControlsTemplate.js +1 -1
  119. package/lib/components/templates/TitleField.d.ts +2 -2
  120. package/lib/components/templates/TitleField.d.ts.map +1 -1
  121. package/lib/components/templates/UnsupportedField.d.ts +2 -2
  122. package/lib/components/templates/UnsupportedField.d.ts.map +1 -1
  123. package/lib/components/templates/UnsupportedField.js +2 -2
  124. package/lib/components/templates/WrapIfAdditionalTemplate.d.ts +2 -2
  125. package/lib/components/templates/WrapIfAdditionalTemplate.d.ts.map +1 -1
  126. package/lib/components/templates/WrapIfAdditionalTemplate.js +1 -1
  127. package/lib/components/templates/index.d.ts +1 -1
  128. package/lib/components/templates/index.d.ts.map +1 -1
  129. package/lib/components/templates/index.js +2 -0
  130. package/lib/components/widgets/AltDateTimeWidget.d.ts +2 -2
  131. package/lib/components/widgets/AltDateTimeWidget.d.ts.map +1 -1
  132. package/lib/components/widgets/AltDateWidget.d.ts +2 -2
  133. package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
  134. package/lib/components/widgets/AltDateWidget.js +2 -2
  135. package/lib/components/widgets/CheckboxWidget.d.ts +2 -2
  136. package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -1
  137. package/lib/components/widgets/CheckboxesWidget.d.ts +2 -2
  138. package/lib/components/widgets/CheckboxesWidget.d.ts.map +1 -1
  139. package/lib/components/widgets/CheckboxesWidget.js +4 -4
  140. package/lib/components/widgets/ColorWidget.d.ts +2 -2
  141. package/lib/components/widgets/ColorWidget.d.ts.map +1 -1
  142. package/lib/components/widgets/DateTimeWidget.d.ts +2 -2
  143. package/lib/components/widgets/DateTimeWidget.d.ts.map +1 -1
  144. package/lib/components/widgets/DateTimeWidget.js +2 -2
  145. package/lib/components/widgets/DateWidget.d.ts +2 -2
  146. package/lib/components/widgets/DateWidget.d.ts.map +1 -1
  147. package/lib/components/widgets/EmailWidget.d.ts +2 -2
  148. package/lib/components/widgets/EmailWidget.d.ts.map +1 -1
  149. package/lib/components/widgets/FileWidget.d.ts +2 -2
  150. package/lib/components/widgets/FileWidget.d.ts.map +1 -1
  151. package/lib/components/widgets/FileWidget.js +6 -4
  152. package/lib/components/widgets/HiddenWidget.d.ts +2 -2
  153. package/lib/components/widgets/HiddenWidget.d.ts.map +1 -1
  154. package/lib/components/widgets/PasswordWidget.d.ts +2 -2
  155. package/lib/components/widgets/PasswordWidget.d.ts.map +1 -1
  156. package/lib/components/widgets/RadioWidget.d.ts +2 -2
  157. package/lib/components/widgets/RadioWidget.d.ts.map +1 -1
  158. package/lib/components/widgets/RadioWidget.js +4 -4
  159. package/lib/components/widgets/RangeWidget.d.ts +2 -2
  160. package/lib/components/widgets/RangeWidget.d.ts.map +1 -1
  161. package/lib/components/widgets/RatingWidget.d.ts +2 -2
  162. package/lib/components/widgets/RatingWidget.d.ts.map +1 -1
  163. package/lib/components/widgets/RatingWidget.js +15 -15
  164. package/lib/components/widgets/SelectWidget.d.ts +2 -2
  165. package/lib/components/widgets/SelectWidget.d.ts.map +1 -1
  166. package/lib/components/widgets/SelectWidget.js +9 -8
  167. package/lib/components/widgets/TextWidget.d.ts +2 -2
  168. package/lib/components/widgets/TextWidget.d.ts.map +1 -1
  169. package/lib/components/widgets/TextareaWidget.d.ts +2 -2
  170. package/lib/components/widgets/TextareaWidget.d.ts.map +1 -1
  171. package/lib/components/widgets/TextareaWidget.js +5 -5
  172. package/lib/components/widgets/TimeWidget.d.ts +2 -2
  173. package/lib/components/widgets/TimeWidget.d.ts.map +1 -1
  174. package/lib/components/widgets/URLWidget.d.ts +2 -2
  175. package/lib/components/widgets/URLWidget.d.ts.map +1 -1
  176. package/lib/components/widgets/UpDownWidget.d.ts +2 -2
  177. package/lib/components/widgets/UpDownWidget.d.ts.map +1 -1
  178. package/lib/components/widgets/index.d.ts +1 -1
  179. package/lib/components/widgets/index.d.ts.map +1 -1
  180. package/lib/getDefaultRegistry.d.ts +1 -1
  181. package/lib/getDefaultRegistry.d.ts.map +1 -1
  182. package/lib/getDefaultRegistry.js +1 -1
  183. package/lib/getTestRegistry.d.ts +1 -1
  184. package/lib/getTestRegistry.d.ts.map +1 -1
  185. package/lib/getTestRegistry.js +1 -1
  186. package/lib/index.d.ts +10 -5
  187. package/lib/index.d.ts.map +1 -1
  188. package/lib/tsconfig.tsbuildinfo +1 -1
  189. package/lib/withTheme.d.ts +3 -3
  190. package/lib/withTheme.d.ts.map +1 -1
  191. package/lib/withTheme.js +6 -6
  192. package/package.json +28 -28
  193. package/src/components/Form.tsx +197 -111
  194. package/src/components/RichDescription.tsx +3 -10
  195. package/src/components/RichHelp.tsx +3 -10
  196. package/src/components/SchemaExamples.tsx +6 -4
  197. package/src/components/fields/ArrayField.tsx +122 -108
  198. package/src/components/fields/BooleanField.tsx +4 -9
  199. package/src/components/fields/CyclicSchemaField.tsx +40 -0
  200. package/src/components/fields/FallbackField.tsx +4 -8
  201. package/src/components/fields/LayoutGridField.tsx +21 -19
  202. package/src/components/fields/LayoutHeaderField.tsx +2 -10
  203. package/src/components/fields/LayoutMultiSchemaField.tsx +15 -10
  204. package/src/components/fields/MultiSchemaField.tsx +202 -218
  205. package/src/components/fields/NullField.tsx +1 -1
  206. package/src/components/fields/NumberField.tsx +8 -10
  207. package/src/components/fields/ObjectField.tsx +52 -40
  208. package/src/components/fields/OptionalDataControlsField.tsx +6 -4
  209. package/src/components/fields/SchemaField.tsx +66 -51
  210. package/src/components/fields/StringField.tsx +4 -15
  211. package/src/components/fields/index.ts +3 -1
  212. package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +2 -9
  213. package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +2 -7
  214. package/src/components/templates/ArrayFieldItemTemplate.tsx +3 -9
  215. package/src/components/templates/ArrayFieldTemplate.tsx +2 -9
  216. package/src/components/templates/ArrayFieldTitleTemplate.tsx +2 -10
  217. package/src/components/templates/BaseInputTemplate.tsx +16 -23
  218. package/src/components/templates/ButtonTemplates/AddButton.tsx +2 -1
  219. package/src/components/templates/ButtonTemplates/IconButton.tsx +16 -7
  220. package/src/components/templates/ButtonTemplates/SubmitButton.tsx +2 -1
  221. package/src/components/templates/ButtonTemplates/index.ts +1 -1
  222. package/src/components/templates/CyclicSchemaExpandTemplate.tsx +31 -0
  223. package/src/components/templates/DescriptionField.tsx +1 -1
  224. package/src/components/templates/ErrorList.tsx +8 -15
  225. package/src/components/templates/FallbackFieldTemplate.tsx +2 -1
  226. package/src/components/templates/FieldErrorTemplate.tsx +8 -8
  227. package/src/components/templates/FieldHelpTemplate.tsx +2 -1
  228. package/src/components/templates/FieldTemplate/FieldTemplate.tsx +2 -8
  229. package/src/components/templates/FieldTemplate/Label.tsx +2 -2
  230. package/src/components/templates/GridTemplate.tsx +1 -1
  231. package/src/components/templates/MultiSchemaFieldTemplate.tsx +1 -1
  232. package/src/components/templates/ObjectFieldTemplate.tsx +2 -7
  233. package/src/components/templates/OptionalDataControlsTemplate.tsx +3 -2
  234. package/src/components/templates/TitleField.tsx +1 -1
  235. package/src/components/templates/UnsupportedField.tsx +4 -3
  236. package/src/components/templates/WrapIfAdditionalTemplate.tsx +2 -9
  237. package/src/components/templates/index.ts +3 -1
  238. package/src/components/widgets/AltDateTimeWidget.tsx +1 -1
  239. package/src/components/widgets/AltDateWidget.tsx +7 -13
  240. package/src/components/widgets/CheckboxWidget.tsx +3 -5
  241. package/src/components/widgets/CheckboxesWidget.tsx +8 -10
  242. package/src/components/widgets/ColorWidget.tsx +2 -1
  243. package/src/components/widgets/DateTimeWidget.tsx +3 -10
  244. package/src/components/widgets/DateWidget.tsx +2 -1
  245. package/src/components/widgets/EmailWidget.tsx +2 -1
  246. package/src/components/widgets/FileWidget.tsx +9 -8
  247. package/src/components/widgets/HiddenWidget.tsx +1 -1
  248. package/src/components/widgets/PasswordWidget.tsx +2 -1
  249. package/src/components/widgets/RadioWidget.tsx +8 -10
  250. package/src/components/widgets/RangeWidget.tsx +1 -1
  251. package/src/components/widgets/RatingWidget.tsx +48 -47
  252. package/src/components/widgets/SelectWidget.tsx +48 -31
  253. package/src/components/widgets/TextWidget.tsx +2 -1
  254. package/src/components/widgets/TextareaWidget.tsx +10 -7
  255. package/src/components/widgets/TimeWidget.tsx +2 -1
  256. package/src/components/widgets/URLWidget.tsx +2 -1
  257. package/src/components/widgets/UpDownWidget.tsx +2 -1
  258. package/src/components/widgets/index.ts +1 -1
  259. package/src/getDefaultRegistry.ts +2 -9
  260. package/src/getTestRegistry.tsx +2 -7
  261. package/src/index.ts +10 -5
  262. package/src/withTheme.tsx +14 -9
@@ -1,4 +1,17 @@
1
- import { FocusEvent, useCallback, useRef, useState } from 'react';
1
+ import type { FocusEvent } from 'react';
2
+ import { memo, useCallback, useMemo, useRef, useState } from 'react';
3
+ import type {
4
+ ErrorSchema,
5
+ FieldPathId,
6
+ FieldPathList,
7
+ FieldProps,
8
+ FormContextType,
9
+ GenericObjectType,
10
+ Registry,
11
+ RJSFMarkedSchema,
12
+ RJSFSchema,
13
+ StrictRJSFSchema,
14
+ } from '@rjsf/utils';
2
15
  import {
3
16
  ADDITIONAL_PROPERTY_FLAG,
4
17
  ANY_OF_KEY,
@@ -9,25 +22,16 @@ import {
9
22
  shouldRenderOptionalField,
10
23
  toFieldPathId,
11
24
  useDeepCompareMemo,
12
- ErrorSchema,
13
- FieldPathId,
14
- FieldPathList,
15
- FieldProps,
16
- FormContextType,
17
- GenericObjectType,
18
25
  ONE_OF_KEY,
19
26
  PROPERTIES_KEY,
20
27
  REF_KEY,
21
- Registry,
22
- RJSFSchema,
23
- StrictRJSFSchema,
24
28
  TranslatableString,
25
29
  } from '@rjsf/utils';
26
30
  import get from 'lodash/get';
27
31
  import has from 'lodash/has';
28
32
  import isObject from 'lodash/isObject';
29
33
  import set from 'lodash/set';
30
- import { Markdown } from 'markdown-to-jsx';
34
+ import { Markdown } from 'markdown-to-jsx/react';
31
35
 
32
36
  import { ADDITIONAL_PROPERTY_KEY_REMOVE } from '../constants';
33
37
 
@@ -38,7 +42,7 @@ import { ADDITIONAL_PROPERTY_KEY_REMOVE } from '../constants';
38
42
  * @returns - True if the field `name` is required, false otherwise
39
43
  */
40
44
  function isRequired<S extends StrictRJSFSchema = RJSFSchema>(schema: S, name: string) {
41
- return Array.isArray(schema.required) && schema.required.indexOf(name) !== -1;
45
+ return Array.isArray(schema.required) && schema.required.includes(name);
42
46
  }
43
47
 
44
48
  /** Returns a default value to be used for a new additional schema property of the given `type`
@@ -86,7 +90,7 @@ interface ObjectFieldPropertyProps<
86
90
 
87
91
  /** The `ObjectFieldProperty` component is used to render the `SchemaField` for a child property of an object
88
92
  */
89
- function ObjectFieldProperty<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
93
+ function ObjectFieldPropertyFn<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
90
94
  props: ObjectFieldPropertyProps<T, S, F>,
91
95
  ) {
92
96
  const {
@@ -125,14 +129,15 @@ function ObjectFieldProperty<T = any, S extends StrictRJSFSchema = RJSFSchema, F
125
129
  */
126
130
  const onPropertyChange = useCallback(
127
131
  (value: T | undefined, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => {
132
+ // Don't set value = undefined for fields added by additionalProperties. Doing so removes them from the
133
+ // formData, which causes them to completely disappear (including the input field for the property name). Unlike
134
+ // fields which are "mandated" by the schema, these fields can be set to undefined by clicking a "delete field"
135
+ // button, so set empty values to the empty string.
136
+ let normalizedValue = value;
128
137
  if (value === undefined && addedByAdditionalProperties) {
129
- // Don't set value = undefined for fields added by additionalProperties. Doing so removes them from the
130
- // formData, which causes them to completely disappear (including the input field for the property name). Unlike
131
- // fields which are "mandated" by the schema, these fields can be set to undefined by clicking a "delete field"
132
- // button, so set empty values to the empty string.
133
- value = '' as unknown as T;
138
+ normalizedValue = '' as unknown as T;
134
139
  }
135
- onChange(value, path, newErrorSchema, id);
140
+ onChange(normalizedValue, path, newErrorSchema, id);
136
141
  },
137
142
  [onChange, addedByAdditionalProperties],
138
143
  );
@@ -193,6 +198,8 @@ function ObjectFieldProperty<T = any, S extends StrictRJSFSchema = RJSFSchema, F
193
198
  );
194
199
  }
195
200
 
201
+ const ObjectFieldProperty = memo(ObjectFieldPropertyFn) as typeof ObjectFieldPropertyFn;
202
+
196
203
  /** The `ObjectField` component is used to render a field in the schema that is of type `object`. It tracks whether an
197
204
  * additional property key was modified and what it was modified to
198
205
  *
@@ -222,8 +229,11 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
222
229
  const { OptionalDataControlsField } = fields;
223
230
  const formDataRef = useRef(formData);
224
231
  formDataRef.current = formData;
225
- const schema: S = schemaUtils.retrieveSchema(rawSchema, formData, true);
226
- const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
232
+ const schema: S = useMemo(
233
+ () => schemaUtils.retrieveSchema(rawSchema, formData, true),
234
+ [schemaUtils, rawSchema, formData],
235
+ );
236
+ const uiOptions = useMemo(() => getUiOptions<T, S, F>(uiSchema, globalUiOptions), [uiSchema, globalUiOptions]);
227
237
  const { properties: schemaProperties = {} } = schema;
228
238
  // All the children will use childFieldPathId if present in the props, falling back to the fieldPathId
229
239
  const childFieldPathId = props.childFieldPathId ?? fieldPathId;
@@ -243,13 +253,14 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
243
253
  * @returns - The name of the next available key from `preferredKey`
244
254
  */
245
255
  const getAvailableKey = useCallback(
246
- (preferredKey: string, formData?: T) => {
256
+ (preferredKey: string, existingFormData?: T) => {
247
257
  const { duplicateKeySuffixSeparator = '-' } = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
248
258
 
249
259
  let index = 0;
250
260
  let newKey = preferredKey;
251
- while (has(formData, newKey)) {
252
- newKey = `${preferredKey}${duplicateKeySuffixSeparator}${++index}`;
261
+ while (has(existingFormData, newKey)) {
262
+ index += 1;
263
+ newKey = `${preferredKey}${duplicateKeySuffixSeparator}${index}`;
253
264
  }
254
265
  return newKey;
255
266
  },
@@ -263,7 +274,6 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
263
274
  if (!(schema.additionalProperties || schema.patternProperties)) {
264
275
  return;
265
276
  }
266
- const { translateString } = registry;
267
277
  const newFormData = { ...formData } as T;
268
278
  const newKey = getAvailableKey('newKey', newFormData);
269
279
  if (schema.patternProperties) {
@@ -279,11 +289,10 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
279
289
  defaultValue = schema.additionalProperties.default;
280
290
  let apSchema = schema.additionalProperties;
281
291
  if (REF_KEY in apSchema) {
282
- const { schemaUtils } = registry;
283
292
  apSchema = schemaUtils.retrieveSchema({ [REF_KEY]: apSchema[REF_KEY] } as S, formData);
284
293
  type = apSchema.type;
285
294
  constValue = apSchema.const;
286
- defaultValue = apSchema.default;
295
+ defaultValue = schemaUtils.getDefaultFormState(apSchema as S, defaultValue as T) as RJSFSchema['default'];
287
296
  }
288
297
  if (!type && (ANY_OF_KEY in apSchema || ONE_OF_KEY in apSchema)) {
289
298
  type = 'object';
@@ -300,7 +309,7 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
300
309
  lastRenamedProperty.current.previousKey = getAvailableKey(newKey, newFormData);
301
310
  }
302
311
  onChange(newFormData, childFieldPathId.path);
303
- }, [formData, onChange, registry, childFieldPathId, getAvailableKey, schema]);
312
+ }, [formData, onChange, translateString, schemaUtils, childFieldPathId, getAvailableKey, schema]);
304
313
 
305
314
  /** Returns a callback function that deals with the rename of a key for an additional property for a schema. That
306
315
  * callback will attempt to rename the key and move the existing data to that key, calling `onChange` when it does.
@@ -319,8 +328,9 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
319
328
  };
320
329
  const newKeys: GenericObjectType = { [oldKey]: actualNewKey };
321
330
  const keyValues = Object.keys(newFormData).map((key) => {
322
- const newKey = newKeys[key] || key;
323
- return { [newKey]: newFormData[key] };
331
+ // `Object.hasOwn` so a falsy rename target (e.g. `""`) isn't dropped.
332
+ const mappedKey = Object.hasOwn(newKeys, key) ? newKeys[key] : key;
333
+ return { [mappedKey]: newFormData[key] };
324
334
  });
325
335
  const renamedObj = Object.assign({}, ...keyValues);
326
336
 
@@ -384,20 +394,22 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
384
394
  // getDisplayLabel() always returns false for object types, so just check the `uiOptions.label`
385
395
  title: uiOptions.label === false ? '' : templateTitle,
386
396
  description: uiOptions.label === false ? undefined : description,
387
- properties: orderedProperties.map((name) => {
388
- const addedByAdditionalProperties = has(schema, [PROPERTIES_KEY, name, ADDITIONAL_PROPERTY_FLAG]);
389
- const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[name];
397
+ properties: orderedProperties.map((propertyName) => {
398
+ const addedByAdditionalProperties = Boolean(
399
+ (schema.properties?.[propertyName] as RJSFMarkedSchema)?.[ADDITIONAL_PROPERTY_FLAG],
400
+ );
401
+ const fieldUiSchema = addedByAdditionalProperties ? uiSchema.additionalProperties : uiSchema[propertyName];
390
402
  const hidden = getUiOptions<T, S, F>(fieldUiSchema).widget === 'hidden';
391
403
  const content = (
392
404
  <ObjectFieldProperty<T, S, F>
393
- key={getStableKey(name)}
394
- propertyName={name}
395
- required={isRequired<S>(schema, name)}
396
- schema={get(schema, [PROPERTIES_KEY, name], {}) as S}
405
+ key={getStableKey(propertyName)}
406
+ propertyName={propertyName}
407
+ required={isRequired<S>(schema, propertyName)}
408
+ schema={get(schema, [PROPERTIES_KEY, propertyName], {}) as S}
397
409
  uiSchema={fieldUiSchema}
398
- errorSchema={get(errorSchema, [name])}
410
+ errorSchema={get(errorSchema, [propertyName])}
399
411
  fieldPathId={childFieldPathId}
400
- formData={get(formData, [name])}
412
+ formData={get(formData, [propertyName])}
401
413
  handleKeyRename={handleKeyRename}
402
414
  handleRemoveProperty={handleRemoveProperty}
403
415
  addedByAdditionalProperties={addedByAdditionalProperties}
@@ -412,7 +424,7 @@ export default function ObjectField<T = any, S extends StrictRJSFSchema = RJSFSc
412
424
  );
413
425
  return {
414
426
  content,
415
- name,
427
+ name: propertyName,
416
428
  readonly,
417
429
  disabled,
418
430
  required,
@@ -1,14 +1,16 @@
1
- import {
1
+ import type {
2
2
  FieldProps,
3
3
  FormContextType,
4
+ OptionalDataControlsTemplateProps,
5
+ RJSFSchema,
6
+ StrictRJSFSchema,
7
+ } from '@rjsf/utils';
8
+ import {
4
9
  getSchemaType,
5
10
  getTemplate,
6
11
  getUiOptions,
7
12
  isFormDataAvailable,
8
13
  optionalControlsId,
9
- OptionalDataControlsTemplateProps,
10
- RJSFSchema,
11
- StrictRJSFSchema,
12
14
  TranslatableString,
13
15
  } from '@rjsf/utils';
14
16
 
@@ -1,8 +1,6 @@
1
- import { useCallback, Component, ComponentType } from 'react';
2
- import {
3
- ADDITIONAL_PROPERTY_FLAG,
4
- ANY_OF_KEY,
5
- descriptionId,
1
+ import type { ComponentType } from 'react';
2
+ import { useCallback, memo } from 'react';
3
+ import type {
6
4
  ErrorSchema,
7
5
  Field,
8
6
  FieldPathId,
@@ -10,28 +8,36 @@ import {
10
8
  FieldProps,
11
9
  FieldTemplateProps,
12
10
  FormContextType,
11
+ Registry,
12
+ RJSFMarkedSchema,
13
+ RJSFSchema,
14
+ StrictRJSFSchema,
15
+ UIOptionsType,
16
+ } from '@rjsf/utils';
17
+ import {
18
+ ADDITIONAL_PROPERTY_FLAG,
19
+ ANY_OF_KEY,
20
+ deepEquals,
21
+ descriptionId,
13
22
  getSchemaType,
14
23
  getTemplate,
15
24
  getUiOptions,
16
25
  ID_KEY,
17
26
  isFormDataAvailable,
18
27
  ONE_OF_KEY,
19
- Registry,
20
28
  resolveUiSchema,
21
- RJSFSchema,
22
- shouldRender,
29
+ RJSF_REF_CYCLE_KEY,
30
+ shallowEquals,
23
31
  shouldRenderOptionalField,
24
- StrictRJSFSchema,
25
32
  toFieldPathId,
26
33
  TranslatableString,
27
34
  UI_OPTIONS_KEY,
28
- UIOptionsType,
29
35
  } from '@rjsf/utils';
30
36
  import isObject from 'lodash/isObject';
31
37
  import omit from 'lodash/omit';
32
38
 
33
39
  /** The map of component type to FieldName */
34
- const COMPONENT_TYPES: { [key: string]: string } = {
40
+ const COMPONENT_TYPES: Record<string, string> = {
35
41
  array: 'ArrayField',
36
42
  boolean: 'BooleanField',
37
43
  integer: 'NumberField',
@@ -55,8 +61,8 @@ function getFieldComponent<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
55
61
  uiOptions: UIOptionsType<T, S, F>,
56
62
  registry: Registry<T, S, F>,
57
63
  ): ComponentType<FieldProps<T, S, F>> {
58
- const field = uiOptions.field;
59
- const { fields } = registry;
64
+ const { field } = uiOptions;
65
+ const { fields, schemaUtils } = registry;
60
66
  if (typeof field === 'function') {
61
67
  return field;
62
68
  }
@@ -74,13 +80,17 @@ function getFieldComponent<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
74
80
  componentName = schemaId;
75
81
  }
76
82
 
77
- // If the type is not defined and the schema uses 'anyOf' or 'oneOf', don't
78
- // render a field and let the MultiSchemaField component handle the form display
79
- if (!componentName && (schema.anyOf || schema.oneOf)) {
83
+ // If the schema uses 'anyOf' or 'oneOf' and is not a pure select (all-constant options),
84
+ // let the MultiSchemaField component handle the form display entirely.
85
+ // ObjectField is excluded: it renders shared properties (defined at the parent schema
86
+ // level) alongside the XxxOfField option selector.
87
+ // All other field types — including primitives and arrays — have no shared renderable
88
+ // properties, so the outer FieldComponent would only produce a spurious duplicate input.
89
+ if ((schema.anyOf || schema.oneOf) && !schemaUtils.isSelect(schema) && componentName !== 'ObjectField') {
80
90
  return () => null;
81
91
  }
82
92
 
83
- return componentName in fields ? fields[componentName] : fields['FallbackField'];
93
+ return componentName in fields ? fields[componentName] : fields.FallbackField;
84
94
  }
85
95
 
86
96
  /** The `SchemaFieldRender` component is the work-horse of react-jsonschema-form, determining what kind of real field to
@@ -108,7 +118,26 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
108
118
  wasPropertyKeyModified = false,
109
119
  } = props;
110
120
  const { schemaUtils, globalFormOptions, globalUiOptions, fields } = registry;
111
- const { AnyOfField: _AnyOfField, OneOfField: _OneOfField } = fields;
121
+ const { AnyOfField: _AnyOfField, OneOfField: _OneOfField, CyclicSchemaField } = fields;
122
+ const fieldId = fieldPathId[ID_KEY];
123
+
124
+ /** Intermediary `onChange` handler for field components that will inject the `id` of the current field into the
125
+ * `onChange` chain if it is not already being provided from a deeper level in the hierarchy
126
+ */
127
+ const handleFieldComponentChange = useCallback(
128
+ (newFormData: T | undefined, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => {
129
+ const theId = id || fieldId;
130
+ return onChange(newFormData, path, newErrorSchema, theId);
131
+ },
132
+ [fieldId, onChange],
133
+ );
134
+
135
+ // Stop $ref cycles: when resolveAllReferences detects a repeated property $ref it tags the schema with this flag.
136
+ // The check must come after all hook calls to satisfy React's rules of hooks.
137
+ if ((_schema as RJSFMarkedSchema)[RJSF_REF_CYCLE_KEY]) {
138
+ return <CyclicSchemaField {...props} />;
139
+ }
140
+
112
141
  const uiSchema = resolveUiSchema<T, S, F>(_schema, _uiSchema, registry);
113
142
  const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
114
143
  const FieldTemplate = getTemplate<'FieldTemplate', T, S, F>('FieldTemplate', registry, uiOptions);
@@ -120,18 +149,6 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
120
149
  const FieldHelpTemplate = getTemplate<'FieldHelpTemplate', T, S, F>('FieldHelpTemplate', registry, uiOptions);
121
150
  const FieldErrorTemplate = getTemplate<'FieldErrorTemplate', T, S, F>('FieldErrorTemplate', registry, uiOptions);
122
151
  const schema = schemaUtils.retrieveSchema(_schema, formData);
123
- const fieldId = fieldPathId[ID_KEY];
124
-
125
- /** Intermediary `onChange` handler for field components that will inject the `id` of the current field into the
126
- * `onChange` chain if it is not already being provided from a deeper level in the hierarchy
127
- */
128
- const handleFieldComponentChange = useCallback(
129
- (formData: T | undefined, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => {
130
- const theId = id || fieldId;
131
- return onChange(formData, path, newErrorSchema, theId);
132
- },
133
- [fieldId, onChange],
134
- );
135
152
 
136
153
  const FieldComponent = getFieldComponent<T, S, F>(schema, uiOptions, registry);
137
154
 
@@ -162,13 +179,13 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
162
179
  if ((ANY_OF_KEY in schema || ONE_OF_KEY in schema) && !isReplacingAnyOrOneOf && !schemaUtils.isSelect(schema)) {
163
180
  if (schema[ANY_OF_KEY]) {
164
181
  XxxOfField = _AnyOfField;
165
- XxxOfOptions = schema[ANY_OF_KEY].map((_schema) =>
166
- schemaUtils.retrieveSchema(isObject(_schema) ? (_schema as S) : ({} as S), formData),
182
+ XxxOfOptions = schema[ANY_OF_KEY].map((xxxOfSchema) =>
183
+ schemaUtils.retrieveSchema(isObject(xxxOfSchema) ? (xxxOfSchema as S) : ({} as S), formData),
167
184
  );
168
185
  } else if (schema[ONE_OF_KEY]) {
169
186
  XxxOfField = _OneOfField;
170
- XxxOfOptions = schema[ONE_OF_KEY].map((_schema) =>
171
- schemaUtils.retrieveSchema(isObject(_schema) ? (_schema as S) : ({} as S), formData),
187
+ XxxOfOptions = schema[ONE_OF_KEY].map((xxxOfSchema) =>
188
+ schemaUtils.retrieveSchema(isObject(xxxOfSchema) ? (xxxOfSchema as S) : ({} as S), formData),
172
189
  );
173
190
  }
174
191
  // When the anyOf/oneOf is an optional data control render AND it does not have form data, hide the label
@@ -224,7 +241,7 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
224
241
  }
225
242
 
226
243
  const description = uiOptions.description || props.schema.description || schema.description || '';
227
- const help = uiOptions.help;
244
+ const { help } = uiOptions;
228
245
  const hidden = uiOptions.widget === 'hidden' || deprecatedHandling === 'hide';
229
246
 
230
247
  const classNames = ['rjsf-field', `rjsf-field-${getSchemaType(schema)}`];
@@ -324,24 +341,22 @@ function SchemaFieldRender<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
324
341
  );
325
342
  }
326
343
 
327
- /** The `SchemaField` component determines whether it is necessary to rerender the component based on any props changes
328
- * and if so, calls the `SchemaFieldRender` component with the props.
344
+ /** The `SchemaField` component wraps `SchemaFieldRender` with a custom memoization comparator that determines whether it is necessary to rerender the component based on any props changes
345
+ * using `experimental_componentUpdateStrategy`.
346
+ *
347
+ * The cast to `typeof SchemaFieldRender` preserves the generic type signature (<T, S, F>) for consumers,
348
+ * since React.memo's return type erases generic parameters.
329
349
  */
330
- class SchemaField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends Component<
331
- FieldProps<T, S, F>
332
- > {
333
- shouldComponentUpdate(nextProps: Readonly<FieldProps<T, S, F>>) {
334
- const {
335
- registry: { globalFormOptions },
336
- } = this.props;
337
- const { experimental_componentUpdateStrategy = 'customDeep' } = globalFormOptions;
338
-
339
- return shouldRender(this, nextProps, this.state, experimental_componentUpdateStrategy);
350
+ const SchemaField = memo(SchemaFieldRender, (prevProps, nextProps) => {
351
+ const { experimental_componentUpdateStrategy = 'customDeep' } = nextProps.registry.globalFormOptions;
352
+ if (experimental_componentUpdateStrategy === 'always') {
353
+ return false; // always re-render — never consider props equal
340
354
  }
341
-
342
- render() {
343
- return <SchemaFieldRender<T, S, F> {...this.props} />;
355
+ if (experimental_componentUpdateStrategy === 'shallow') {
356
+ return shallowEquals(prevProps, nextProps);
344
357
  }
345
- }
358
+ // default: 'customDeep'
359
+ return deepEquals(prevProps, nextProps);
360
+ }) as unknown as typeof SchemaFieldRender;
346
361
 
347
362
  export default SchemaField;
@@ -1,15 +1,6 @@
1
1
  import { useCallback } from 'react';
2
- import {
3
- getWidget,
4
- getUiOptions,
5
- optionsList,
6
- hasWidget,
7
- FieldProps,
8
- FormContextType,
9
- RJSFSchema,
10
- StrictRJSFSchema,
11
- ErrorSchema,
12
- } from '@rjsf/utils';
2
+ import type { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema, ErrorSchema } from '@rjsf/utils';
3
+ import { getWidget, getUiOptions, optionsList, hasWidget } from '@rjsf/utils';
13
4
 
14
5
  /** The `StringField` component is used to render a schema field that represents a string type
15
6
  *
@@ -48,10 +39,8 @@ function StringField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
48
39
  const label = uiTitle ?? title ?? schemaTitle ?? name;
49
40
  const Widget = getWidget<T, S, F>(schema, widget, widgets);
50
41
  const onWidgetChange = useCallback(
51
- (value: T | undefined, errorSchema?: ErrorSchema, id?: string) => {
52
- // String field change passes an empty path array to the parent field which adds the appropriate path
53
- return onChange(value, fieldPathId.path, errorSchema, id);
54
- },
42
+ (value: T | undefined, errorSchema?: ErrorSchema, id?: string) =>
43
+ onChange(value, fieldPathId.path, errorSchema, id),
55
44
  [onChange, fieldPathId],
56
45
  );
57
46
  return (
@@ -1,7 +1,8 @@
1
- import { Field, FormContextType, RegistryFieldsType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
1
+ import type { Field, FormContextType, RegistryFieldsType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
2
 
3
3
  import ArrayField from './ArrayField';
4
4
  import BooleanField from './BooleanField';
5
+ import CyclicSchemaField from './CyclicSchemaField';
5
6
  import FallbackField from './FallbackField';
6
7
  import LayoutGridField from './LayoutGridField';
7
8
  import LayoutHeaderField from './LayoutHeaderField';
@@ -24,6 +25,7 @@ function fields<
24
25
  ArrayField: ArrayField as unknown as Field<T, S, F>,
25
26
  // ArrayField falls back to SchemaField if ArraySchemaField is not defined, which it isn't by default
26
27
  BooleanField,
28
+ CyclicSchemaField,
27
29
  FallbackField,
28
30
  LayoutGridField,
29
31
  LayoutHeaderField,
@@ -1,12 +1,5 @@
1
- import {
2
- descriptionId,
3
- getTemplate,
4
- getUiOptions,
5
- ArrayFieldDescriptionProps,
6
- FormContextType,
7
- RJSFSchema,
8
- StrictRJSFSchema,
9
- } from '@rjsf/utils';
1
+ import type { ArrayFieldDescriptionProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
+ import { descriptionId, getTemplate, getUiOptions } from '@rjsf/utils';
10
3
 
11
4
  /** The `ArrayFieldDescriptionTemplate` component renders a `DescriptionFieldTemplate` with an `id` derived from
12
5
  * the `fieldPathId`.
@@ -1,10 +1,5 @@
1
- import {
2
- ArrayFieldItemButtonsTemplateProps,
3
- buttonId,
4
- FormContextType,
5
- RJSFSchema,
6
- StrictRJSFSchema,
7
- } from '@rjsf/utils';
1
+ import type { ArrayFieldItemButtonsTemplateProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
+ import { buttonId } from '@rjsf/utils';
8
3
 
9
4
  /** The `ArrayFieldTemplateItemButtons` component is the template used to render the buttons associate3d with items of
10
5
  * an array.
@@ -1,12 +1,6 @@
1
- import { CSSProperties } from 'react';
2
- import {
3
- ArrayFieldItemTemplateProps,
4
- FormContextType,
5
- getTemplate,
6
- getUiOptions,
7
- RJSFSchema,
8
- StrictRJSFSchema,
9
- } from '@rjsf/utils';
1
+ import type { CSSProperties } from 'react';
2
+ import type { ArrayFieldItemTemplateProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
3
+ import { getTemplate, getUiOptions } from '@rjsf/utils';
10
4
 
11
5
  /** The `ArrayFieldItemTemplate` component is the template used to render an items of an array.
12
6
  *
@@ -1,12 +1,5 @@
1
- import {
2
- getTemplate,
3
- getUiOptions,
4
- ArrayFieldTemplateProps,
5
- FormContextType,
6
- RJSFSchema,
7
- StrictRJSFSchema,
8
- buttonId,
9
- } from '@rjsf/utils';
1
+ import type { ArrayFieldTemplateProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
+ import { getTemplate, getUiOptions, buttonId } from '@rjsf/utils';
10
3
 
11
4
  /** The `ArrayFieldTemplate` component is the template used to render all items in an array.
12
5
  *
@@ -1,13 +1,5 @@
1
- import {
2
- getTemplate,
3
- getUiOptions,
4
- titleId,
5
- ArrayFieldTitleProps,
6
- FormContextType,
7
- RJSFSchema,
8
- StrictRJSFSchema,
9
- TemplatesType,
10
- } from '@rjsf/utils';
1
+ import type { ArrayFieldTitleProps, FormContextType, RJSFSchema, StrictRJSFSchema, TemplatesType } from '@rjsf/utils';
2
+ import { getTemplate, getUiOptions, titleId } from '@rjsf/utils';
11
3
 
12
4
  /** The `ArrayFieldTitleTemplate` component renders a `TitleFieldTemplate` with an `id` derived from
13
5
  * the `fieldPathId`.
@@ -1,13 +1,7 @@
1
- import { ChangeEvent, FocusEvent, MouseEvent, useCallback } from 'react';
2
- import {
3
- ariaDescribedByIds,
4
- BaseInputTemplateProps,
5
- examplesId,
6
- getInputProps,
7
- FormContextType,
8
- RJSFSchema,
9
- StrictRJSFSchema,
10
- } from '@rjsf/utils';
1
+ import type { ChangeEvent, FocusEvent, MouseEvent } from 'react';
2
+ import { useCallback } from 'react';
3
+ import type { BaseInputTemplateProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
4
+ import { ariaDescribedByIds, examplesId, getInputProps } from '@rjsf/utils';
11
5
 
12
6
  import SchemaExamples from '../SchemaExamples';
13
7
 
@@ -49,6 +43,7 @@ export default function BaseInputTemplate<
49
43
  // Note: since React 15.2.0 we can't forward unknown element attributes, so we
50
44
  // exclude the "options" and "schema" ones here.
51
45
  if (!id) {
46
+ // oxlint-disable-next-line no-console
52
47
  console.log('No id for', props);
53
48
  throw new Error(`no id for props ${JSON.stringify(props)}`);
54
49
  }
@@ -64,19 +59,17 @@ export default function BaseInputTemplate<
64
59
  inputValue = value == null ? '' : value;
65
60
  }
66
61
 
67
- const _onChange = useCallback(
68
- ({ target: { value } }: ChangeEvent<HTMLInputElement>) => onChange(value === '' ? options.emptyValue : value),
62
+ const handleChange = useCallback(
63
+ ({ target: { value: newValue } }: ChangeEvent<HTMLInputElement>) =>
64
+ onChange(newValue === '' ? options.emptyValue : newValue),
69
65
  [onChange, options],
70
66
  );
71
- const _onBlur = useCallback(
72
- ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.value),
73
- [onBlur, id],
74
- );
75
- const _onFocus = useCallback(
76
- ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.value),
67
+ const handleBlur = useCallback(({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target?.value), [onBlur, id]);
68
+ const handleFocus = useCallback(
69
+ ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target?.value),
77
70
  [onFocus, id],
78
71
  );
79
- const _onClear = useCallback(
72
+ const handleClear = useCallback(
80
73
  (e: MouseEvent) => {
81
74
  e.preventDefault();
82
75
  e.stopPropagation();
@@ -97,13 +90,13 @@ export default function BaseInputTemplate<
97
90
  value={inputValue}
98
91
  {...inputProps}
99
92
  list={schema.examples ? examplesId(id) : undefined}
100
- onChange={onChangeOverride || _onChange}
101
- onBlur={_onBlur}
102
- onFocus={_onFocus}
93
+ onChange={onChangeOverride || handleChange}
94
+ onBlur={handleBlur}
95
+ onFocus={handleFocus}
103
96
  aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
104
97
  />
105
98
  {options.allowClearTextInputs && !readonly && !disabled && inputValue && (
106
- <ClearButton registry={registry} onClick={_onClear} />
99
+ <ClearButton registry={registry} onClick={handleClear} />
107
100
  )}
108
101
  <SchemaExamples id={id} schema={schema} />
109
102
  </>
@@ -1,4 +1,5 @@
1
- import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
1
+ import type { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
+ import { TranslatableString } from '@rjsf/utils';
2
3
 
3
4
  import IconButton from './IconButton';
4
5