@rjsf/core 6.0.0-beta.2 → 6.0.0-beta.21

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 (114) hide show
  1. package/dist/core.umd.js +705 -471
  2. package/dist/{index.js → index.cjs} +1094 -844
  3. package/dist/index.cjs.map +7 -0
  4. package/dist/index.esm.js +1053 -774
  5. package/dist/index.esm.js.map +4 -4
  6. package/lib/components/Form.d.ts +88 -23
  7. package/lib/components/Form.d.ts.map +1 -1
  8. package/lib/components/Form.js +213 -151
  9. package/lib/components/fields/ArrayField.d.ts +17 -7
  10. package/lib/components/fields/ArrayField.d.ts.map +1 -1
  11. package/lib/components/fields/ArrayField.js +116 -70
  12. package/lib/components/fields/BooleanField.d.ts.map +1 -1
  13. package/lib/components/fields/BooleanField.js +7 -2
  14. package/lib/components/fields/LayoutGridField.d.ts +27 -25
  15. package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
  16. package/lib/components/fields/LayoutGridField.js +83 -59
  17. package/lib/components/fields/LayoutHeaderField.d.ts +1 -1
  18. package/lib/components/fields/LayoutHeaderField.js +3 -3
  19. package/lib/components/fields/LayoutMultiSchemaField.js +6 -5
  20. package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
  21. package/lib/components/fields/MultiSchemaField.js +13 -9
  22. package/lib/components/fields/NullField.js +3 -3
  23. package/lib/components/fields/NumberField.d.ts.map +1 -1
  24. package/lib/components/fields/NumberField.js +3 -3
  25. package/lib/components/fields/ObjectField.d.ts +3 -3
  26. package/lib/components/fields/ObjectField.d.ts.map +1 -1
  27. package/lib/components/fields/ObjectField.js +34 -34
  28. package/lib/components/fields/OptionalDataControlsField.d.ts +8 -0
  29. package/lib/components/fields/OptionalDataControlsField.d.ts.map +1 -0
  30. package/lib/components/fields/OptionalDataControlsField.js +43 -0
  31. package/lib/components/fields/SchemaField.d.ts.map +1 -1
  32. package/lib/components/fields/SchemaField.js +17 -17
  33. package/lib/components/fields/StringField.d.ts.map +1 -1
  34. package/lib/components/fields/StringField.js +7 -2
  35. package/lib/components/fields/index.d.ts.map +1 -1
  36. package/lib/components/fields/index.js +2 -0
  37. package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +1 -1
  38. package/lib/components/templates/ArrayFieldDescriptionTemplate.js +3 -3
  39. package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +2 -2
  40. package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
  41. package/lib/components/templates/ArrayFieldTemplate.js +4 -3
  42. package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +1 -1
  43. package/lib/components/templates/ArrayFieldTitleTemplate.d.ts.map +1 -1
  44. package/lib/components/templates/ArrayFieldTitleTemplate.js +3 -3
  45. package/lib/components/templates/ButtonTemplates/AddButton.d.ts +1 -1
  46. package/lib/components/templates/ButtonTemplates/AddButton.d.ts.map +1 -1
  47. package/lib/components/templates/ButtonTemplates/AddButton.js +2 -2
  48. package/lib/components/templates/FieldErrorTemplate.js +2 -2
  49. package/lib/components/templates/FieldHelpTemplate.js +2 -2
  50. package/lib/components/templates/MultiSchemaFieldTemplate.d.ts +8 -0
  51. package/lib/components/templates/MultiSchemaFieldTemplate.d.ts.map +1 -0
  52. package/lib/components/templates/MultiSchemaFieldTemplate.js +10 -0
  53. package/lib/components/templates/ObjectFieldTemplate.d.ts.map +1 -1
  54. package/lib/components/templates/ObjectFieldTemplate.js +3 -2
  55. package/lib/components/templates/OptionalDataControlsTemplate.d.ts +11 -0
  56. package/lib/components/templates/OptionalDataControlsTemplate.d.ts.map +1 -0
  57. package/lib/components/templates/OptionalDataControlsTemplate.js +20 -0
  58. package/lib/components/templates/TitleField.d.ts.map +1 -1
  59. package/lib/components/templates/TitleField.js +2 -2
  60. package/lib/components/templates/UnsupportedField.js +3 -3
  61. package/lib/components/templates/index.d.ts.map +1 -1
  62. package/lib/components/templates/index.js +4 -0
  63. package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
  64. package/lib/components/widgets/AltDateWidget.js +15 -18
  65. package/lib/components/widgets/CheckboxesWidget.js +2 -2
  66. package/lib/getDefaultRegistry.d.ts.map +1 -1
  67. package/lib/getDefaultRegistry.js +2 -1
  68. package/lib/getTestRegistry.d.ts +5 -0
  69. package/lib/getTestRegistry.d.ts.map +1 -0
  70. package/lib/getTestRegistry.js +19 -0
  71. package/lib/index.d.ts +2 -1
  72. package/lib/index.d.ts.map +1 -1
  73. package/lib/index.js +2 -1
  74. package/lib/tsconfig.tsbuildinfo +1 -1
  75. package/package.json +18 -19
  76. package/src/components/Form.tsx +306 -177
  77. package/src/components/fields/ArrayField.tsx +127 -80
  78. package/src/components/fields/BooleanField.tsx +12 -3
  79. package/src/components/fields/LayoutGridField.tsx +95 -88
  80. package/src/components/fields/LayoutHeaderField.tsx +3 -3
  81. package/src/components/fields/LayoutMultiSchemaField.tsx +5 -5
  82. package/src/components/fields/MultiSchemaField.tsx +51 -35
  83. package/src/components/fields/NullField.tsx +3 -3
  84. package/src/components/fields/NumberField.tsx +11 -3
  85. package/src/components/fields/ObjectField.tsx +47 -53
  86. package/src/components/fields/OptionalDataControlsField.tsx +84 -0
  87. package/src/components/fields/SchemaField.tsx +24 -30
  88. package/src/components/fields/StringField.tsx +12 -3
  89. package/src/components/fields/index.ts +2 -0
  90. package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +3 -3
  91. package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +5 -5
  92. package/src/components/templates/ArrayFieldTemplate.tsx +9 -5
  93. package/src/components/templates/ArrayFieldTitleTemplate.tsx +4 -3
  94. package/src/components/templates/BaseInputTemplate.tsx +3 -3
  95. package/src/components/templates/ButtonTemplates/AddButton.tsx +2 -0
  96. package/src/components/templates/FieldErrorTemplate.tsx +2 -2
  97. package/src/components/templates/FieldHelpTemplate.tsx +2 -2
  98. package/src/components/templates/MultiSchemaFieldTemplate.tsx +20 -0
  99. package/src/components/templates/ObjectFieldTemplate.tsx +10 -5
  100. package/src/components/templates/OptionalDataControlsTemplate.tsx +43 -0
  101. package/src/components/templates/TitleField.tsx +6 -1
  102. package/src/components/templates/UnsupportedField.tsx +3 -3
  103. package/src/components/templates/WrapIfAdditionalTemplate.tsx +1 -1
  104. package/src/components/templates/index.ts +4 -0
  105. package/src/components/widgets/AltDateWidget.tsx +21 -23
  106. package/src/components/widgets/CheckboxWidget.tsx +2 -2
  107. package/src/components/widgets/CheckboxesWidget.tsx +3 -3
  108. package/src/components/widgets/RadioWidget.tsx +1 -1
  109. package/src/components/widgets/SelectWidget.tsx +1 -1
  110. package/src/components/widgets/TextareaWidget.tsx +1 -1
  111. package/src/getDefaultRegistry.ts +10 -1
  112. package/src/getTestRegistry.tsx +34 -0
  113. package/src/index.ts +2 -1
  114. package/dist/index.js.map +0 -7
@@ -10,7 +10,7 @@ import {
10
10
  } from '@rjsf/utils';
11
11
 
12
12
  /** The `ArrayFieldTitleTemplate` component renders a `TitleFieldTemplate` with an `id` derived from
13
- * the `idSchema`.
13
+ * the `fieldPathId`.
14
14
  *
15
15
  * @param props - The `ArrayFieldTitleProps` for the component
16
16
  */
@@ -19,7 +19,7 @@ export default function ArrayFieldTitleTemplate<
19
19
  S extends StrictRJSFSchema = RJSFSchema,
20
20
  F extends FormContextType = any,
21
21
  >(props: ArrayFieldTitleProps<T, S, F>) {
22
- const { idSchema, title, schema, uiSchema, required, registry } = props;
22
+ const { fieldPathId, title, schema, uiSchema, required, registry, optionalDataControl } = props;
23
23
  const options = getUiOptions<T, S, F>(uiSchema, registry.globalUiOptions);
24
24
  const { label: displayLabel = true } = options;
25
25
  if (!title || !displayLabel) {
@@ -32,12 +32,13 @@ export default function ArrayFieldTitleTemplate<
32
32
  );
33
33
  return (
34
34
  <TitleFieldTemplate
35
- id={titleId<T>(idSchema)}
35
+ id={titleId(fieldPathId)}
36
36
  title={title}
37
37
  required={required}
38
38
  schema={schema}
39
39
  uiSchema={uiSchema}
40
40
  registry={registry}
41
+ optionalDataControl={optionalDataControl}
41
42
  />
42
43
  );
43
44
  }
@@ -85,14 +85,14 @@ export default function BaseInputTemplate<
85
85
  autoFocus={autofocus}
86
86
  value={inputValue}
87
87
  {...inputProps}
88
- list={schema.examples ? examplesId<T>(id) : undefined}
88
+ list={schema.examples ? examplesId(id) : undefined}
89
89
  onChange={onChangeOverride || _onChange}
90
90
  onBlur={_onBlur}
91
91
  onFocus={_onFocus}
92
- aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
92
+ aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
93
93
  />
94
94
  {Array.isArray(schema.examples) && (
95
- <datalist key={`datalist_${id}`} id={examplesId<T>(id)}>
95
+ <datalist key={`datalist_${id}`} id={examplesId(id)}>
96
96
  {(schema.examples as string[])
97
97
  .concat(schema.default && !schema.examples.includes(schema.default) ? ([schema.default] as string[]) : [])
98
98
  .map((example: any) => {
@@ -5,6 +5,7 @@ import IconButton from './IconButton';
5
5
  /** The `AddButton` renders a button that represent the `Add` action on a form
6
6
  */
7
7
  export default function AddButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
8
+ id,
8
9
  className,
9
10
  onClick,
10
11
  disabled,
@@ -15,6 +16,7 @@ export default function AddButton<T = any, S extends StrictRJSFSchema = RJSFSche
15
16
  <div className='row'>
16
17
  <p className={`col-xs-3 col-xs-offset-9 text-right ${className}`}>
17
18
  <IconButton
19
+ id={id}
18
20
  iconType='info'
19
21
  icon='plus'
20
22
  className='btn-add col-xs-12'
@@ -9,11 +9,11 @@ export default function FieldErrorTemplate<
9
9
  S extends StrictRJSFSchema = RJSFSchema,
10
10
  F extends FormContextType = any,
11
11
  >(props: FieldErrorProps<T, S, F>) {
12
- const { errors = [], idSchema } = props;
12
+ const { errors = [], fieldPathId } = props;
13
13
  if (errors.length === 0) {
14
14
  return null;
15
15
  }
16
- const id = errorId<T>(idSchema);
16
+ const id = errorId(fieldPathId);
17
17
 
18
18
  return (
19
19
  <div>
@@ -9,11 +9,11 @@ export default function FieldHelpTemplate<
9
9
  S extends StrictRJSFSchema = RJSFSchema,
10
10
  F extends FormContextType = any,
11
11
  >(props: FieldHelpProps<T, S, F>) {
12
- const { idSchema, help } = props;
12
+ const { fieldPathId, help } = props;
13
13
  if (!help) {
14
14
  return null;
15
15
  }
16
- const id = helpId<T>(idSchema);
16
+ const id = helpId(fieldPathId);
17
17
  if (typeof help === 'string') {
18
18
  return (
19
19
  <p id={id} className='help-block'>
@@ -0,0 +1,20 @@
1
+ import { FormContextType, MultiSchemaFieldTemplateProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
+
3
+ /** The `MultiSchemaFieldTemplate` component renders the layout for the MultiSchemaField, which supports choosing
4
+ * a schema from a list of schemas defined using `anyOf` or `oneOf`.
5
+ *
6
+ * @param props - The `MultiSchemaFieldTemplate` to be rendered
7
+ */
8
+ export default function MultiSchemaFieldTemplate<
9
+ T = any,
10
+ S extends StrictRJSFSchema = RJSFSchema,
11
+ F extends FormContextType = any,
12
+ >(props: MultiSchemaFieldTemplateProps<T, S, F>) {
13
+ const { selector, optionSchemaField } = props;
14
+ return (
15
+ <div className='panel panel-default panel-body'>
16
+ <div className='form-group'>{selector}</div>
17
+ {optionSchemaField}
18
+ </div>
19
+ );
20
+ }
@@ -24,11 +24,13 @@ export default function ObjectFieldTemplate<
24
24
  F extends FormContextType = any,
25
25
  >(props: ObjectFieldTemplateProps<T, S, F>) {
26
26
  const {
27
+ className,
27
28
  description,
28
29
  disabled,
29
30
  formData,
30
- idSchema,
31
+ fieldPathId,
31
32
  onAddClick,
33
+ optionalDataControl,
32
34
  properties,
33
35
  readonly,
34
36
  registry,
@@ -44,35 +46,38 @@ export default function ObjectFieldTemplate<
44
46
  registry,
45
47
  options,
46
48
  );
49
+ const showOptionalDataControlInTitle = !readonly && !disabled;
47
50
  // Button templates are not overridden in the uiSchema
48
51
  const {
49
52
  ButtonTemplates: { AddButton },
50
53
  } = registry.templates;
51
54
  return (
52
- <fieldset id={idSchema.$id}>
55
+ <fieldset className={className} id={fieldPathId.$id}>
53
56
  {title && (
54
57
  <TitleFieldTemplate
55
- id={titleId<T>(idSchema)}
58
+ id={titleId(fieldPathId)}
56
59
  title={title}
57
60
  required={required}
58
61
  schema={schema}
59
62
  uiSchema={uiSchema}
60
63
  registry={registry}
64
+ optionalDataControl={showOptionalDataControlInTitle ? optionalDataControl : undefined}
61
65
  />
62
66
  )}
63
67
  {description && (
64
68
  <DescriptionFieldTemplate
65
- id={descriptionId<T>(idSchema)}
69
+ id={descriptionId(fieldPathId)}
66
70
  description={description}
67
71
  schema={schema}
68
72
  uiSchema={uiSchema}
69
73
  registry={registry}
70
74
  />
71
75
  )}
76
+ {!showOptionalDataControlInTitle ? optionalDataControl : undefined}
72
77
  {properties.map((prop: ObjectFieldTemplatePropertyType) => prop.content)}
73
78
  {canExpand<T, S, F>(schema, uiSchema, formData) && (
74
79
  <AddButton
75
- id={buttonId<T>(idSchema, 'add')}
80
+ id={buttonId(fieldPathId, 'add')}
76
81
  className='rjsf-object-property-expand'
77
82
  onClick={onAddClick(schema)}
78
83
  disabled={disabled || readonly}
@@ -0,0 +1,43 @@
1
+ import { FormContextType, OptionalDataControlsTemplateProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
+
3
+ import IconButton from './ButtonTemplates/IconButton';
4
+
5
+ /** The OptionalDataControlsTemplate renders one of three different states. If
6
+ * there is an `onAddClick()` function, it renders the "Add" button. If there is
7
+ * an `onRemoveClick()` function, it renders the "Remove" button. Otherwise it
8
+ * renders the "No data found" section. All of them use the `label` as either
9
+ * the `title` of buttons or simply outputting it.
10
+ *
11
+ * @param props - The `OptionalDataControlsTemplateProps` for the template
12
+ */
13
+ export default function OptionalDataControlsTemplate<
14
+ T = any,
15
+ S extends StrictRJSFSchema = RJSFSchema,
16
+ F extends FormContextType = any,
17
+ >(props: OptionalDataControlsTemplateProps<T, S, F>) {
18
+ const { id, registry, label, onAddClick, onRemoveClick } = props;
19
+ if (onAddClick) {
20
+ return (
21
+ <IconButton
22
+ id={id}
23
+ registry={registry}
24
+ icon='plus'
25
+ className='rjsf-add-optional-data btn-sm'
26
+ onClick={onAddClick}
27
+ title={label}
28
+ />
29
+ );
30
+ } else if (onRemoveClick) {
31
+ return (
32
+ <IconButton
33
+ id={id}
34
+ registry={registry}
35
+ icon='remove'
36
+ className='rjsf-remove-optional-data btn-sm'
37
+ onClick={onRemoveClick}
38
+ title={label}
39
+ />
40
+ );
41
+ }
42
+ return <em id={id}>{label}</em>;
43
+ }
@@ -9,11 +9,16 @@ const REQUIRED_FIELD_SYMBOL = '*';
9
9
  export default function TitleField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
10
10
  props: TitleFieldProps<T, S, F>,
11
11
  ) {
12
- const { id, title, required } = props;
12
+ const { id, title, required, optionalDataControl } = props;
13
13
  return (
14
14
  <legend id={id}>
15
15
  {title}
16
16
  {required && <span className='required'>{REQUIRED_FIELD_SYMBOL}</span>}
17
+ {optionalDataControl && (
18
+ <span className='pull-right' style={{ marginBottom: '2px' }}>
19
+ {optionalDataControl}
20
+ </span>
21
+ )}
17
22
  </legend>
18
23
  );
19
24
  }
@@ -9,13 +9,13 @@ import Markdown from 'markdown-to-jsx';
9
9
  function UnsupportedField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
10
10
  props: UnsupportedFieldProps<T, S, F>,
11
11
  ) {
12
- const { schema, idSchema, reason, registry } = props;
12
+ const { schema, fieldPathId, reason, registry } = props;
13
13
  const { translateString } = registry;
14
14
  let translateEnum: TranslatableString = TranslatableString.UnsupportedField;
15
15
  const translateParams: string[] = [];
16
- if (idSchema && idSchema.$id) {
16
+ if (fieldPathId && fieldPathId.$id) {
17
17
  translateEnum = TranslatableString.UnsupportedFieldWithId;
18
- translateParams.push(idSchema.$id);
18
+ translateParams.push(fieldPathId.$id);
19
19
  }
20
20
  if (reason) {
21
21
  translateEnum =
@@ -75,7 +75,7 @@ export default function WrapIfAdditionalTemplate<
75
75
  <div className='form-additional form-group col-xs-5'>{children}</div>
76
76
  <div className='col-xs-2'>
77
77
  <RemoveButton
78
- id={buttonId<T>(id, 'remove')}
78
+ id={buttonId(id, 'remove')}
79
79
  className='rjsf-object-property-remove btn-block'
80
80
  style={{ border: '0' }}
81
81
  disabled={disabled || readonly}
@@ -13,7 +13,9 @@ import FieldTemplate from './FieldTemplate';
13
13
  import FieldErrorTemplate from './FieldErrorTemplate';
14
14
  import FieldHelpTemplate from './FieldHelpTemplate';
15
15
  import GridTemplate from './GridTemplate';
16
+ import MultiSchemaFieldTemplate from './MultiSchemaFieldTemplate';
16
17
  import ObjectFieldTemplate from './ObjectFieldTemplate';
18
+ import OptionalDataControlsTemplate from './OptionalDataControlsTemplate';
17
19
  import TitleField from './TitleField';
18
20
  import UnsupportedField from './UnsupportedField';
19
21
  import WrapIfAdditionalTemplate from './WrapIfAdditionalTemplate';
@@ -37,7 +39,9 @@ function templates<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends F
37
39
  FieldErrorTemplate,
38
40
  FieldHelpTemplate,
39
41
  GridTemplate,
42
+ MultiSchemaFieldTemplate,
40
43
  ObjectFieldTemplate,
44
+ OptionalDataControlsTemplate,
41
45
  TitleFieldTemplate: TitleField,
42
46
  UnsupportedFieldTemplate: UnsupportedField,
43
47
  WrapIfAdditionalTemplate,
@@ -1,4 +1,4 @@
1
- import { MouseEvent, useCallback, useEffect, useReducer, useState } from 'react';
1
+ import { MouseEvent, useCallback, useEffect, useState } from 'react';
2
2
  import {
3
3
  ariaDescribedByIds,
4
4
  dateRangeOptions,
@@ -61,7 +61,7 @@ function DateElement<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
61
61
  onFocus={onFocus}
62
62
  registry={registry}
63
63
  label=''
64
- aria-describedby={ariaDescribedByIds<T>(rootId)}
64
+ aria-describedby={ariaDescribedByIds(rootId)}
65
65
  />
66
66
  );
67
67
  }
@@ -84,29 +84,27 @@ function AltDateWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exten
84
84
  value,
85
85
  }: WidgetProps<T, S, F>) {
86
86
  const { translateString } = registry;
87
- const [lastValue, setLastValue] = useState(value);
88
- const [state, setState] = useReducer(
89
- (state: DateObject, action: Partial<DateObject>) => {
90
- return { ...state, ...action };
91
- },
92
- parseDateString(value, time),
93
- );
87
+ const [state, setState] = useState(parseDateString(value, time));
94
88
 
95
89
  useEffect(() => {
96
- const stateValue = toDateString(state, time);
97
- if (readyForChange(state) && stateValue !== value) {
98
- // The user changed the date to a new valid data via the comboboxes, so call onChange
99
- onChange(stateValue);
100
- } else if (lastValue !== value) {
101
- // We got a new value in the props
102
- setLastValue(value);
103
- setState(parseDateString(value, time));
104
- }
105
- }, [time, value, onChange, state, lastValue]);
90
+ setState(parseDateString(value, time));
91
+ }, [time, value]);
92
+
93
+ const handleChange = useCallback(
94
+ (property: keyof DateObject, value: string) => {
95
+ const nextState = {
96
+ ...state,
97
+ [property]: typeof value === 'undefined' ? -1 : value,
98
+ };
106
99
 
107
- const handleChange = useCallback((property: keyof DateObject, value: string) => {
108
- setState({ [property]: value });
109
- }, []);
100
+ if (readyForChange(nextState)) {
101
+ onChange(toDateString(nextState, time));
102
+ } else {
103
+ setState(nextState);
104
+ }
105
+ },
106
+ [state, onChange, time],
107
+ );
110
108
 
111
109
  const handleSetNow = useCallback(
112
110
  (event: MouseEvent<HTMLAnchorElement>) => {
@@ -117,7 +115,7 @@ function AltDateWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exten
117
115
  const nextState = parseDateString(new Date().toJSON(), time);
118
116
  onChange(toDateString(nextState, time));
119
117
  },
120
- [disabled, readonly, time],
118
+ [disabled, readonly, time, onChange],
121
119
  );
122
120
 
123
121
  const handleClear = useCallback(
@@ -62,7 +62,7 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
62
62
  <div className={`checkbox ${disabled || readonly ? 'disabled' : ''}`}>
63
63
  {!hideLabel && description && (
64
64
  <DescriptionFieldTemplate
65
- id={descriptionId<T>(id)}
65
+ id={descriptionId(id)}
66
66
  description={description}
67
67
  schema={schema}
68
68
  uiSchema={uiSchema}
@@ -81,7 +81,7 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
81
81
  onChange={handleChange}
82
82
  onBlur={handleBlur}
83
83
  onFocus={handleFocus}
84
- aria-describedby={ariaDescribedByIds<T>(id)}
84
+ aria-describedby={ariaDescribedByIds(id)}
85
85
  />
86
86
  {labelValue(<span>{label}</span>, hideLabel)}
87
87
  </label>
@@ -33,13 +33,13 @@ function CheckboxesWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
33
33
  const handleBlur = useCallback(
34
34
  ({ target }: FocusEvent<HTMLInputElement>) =>
35
35
  onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue)),
36
- [onBlur, id],
36
+ [onBlur, id, enumOptions, emptyValue],
37
37
  );
38
38
 
39
39
  const handleFocus = useCallback(
40
40
  ({ target }: FocusEvent<HTMLInputElement>) =>
41
41
  onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue)),
42
- [onFocus, id],
42
+ [onFocus, id, enumOptions, emptyValue],
43
43
  );
44
44
  return (
45
45
  <div className='checkboxes' id={id}>
@@ -70,7 +70,7 @@ function CheckboxesWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
70
70
  onChange={handleChange}
71
71
  onBlur={handleBlur}
72
72
  onFocus={handleFocus}
73
- aria-describedby={ariaDescribedByIds<T>(id)}
73
+ aria-describedby={ariaDescribedByIds(id)}
74
74
  />
75
75
  <span>{option.label}</span>
76
76
  </span>
@@ -65,7 +65,7 @@ function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
65
65
  onChange={handleChange}
66
66
  onBlur={handleBlur}
67
67
  onFocus={handleFocus}
68
- aria-describedby={ariaDescribedByIds<T>(id)}
68
+ aria-describedby={ariaDescribedByIds(id)}
69
69
  />
70
70
  <span>{option.label}</span>
71
71
  </span>
@@ -83,7 +83,7 @@ function SelectWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
83
83
  onBlur={handleBlur}
84
84
  onFocus={handleFocus}
85
85
  onChange={handleChange}
86
- aria-describedby={ariaDescribedByIds<T>(id)}
86
+ aria-describedby={ariaDescribedByIds(id)}
87
87
  >
88
88
  {showPlaceholderOption && <option value=''>{placeholder}</option>}
89
89
  {Array.isArray(enumOptions) &&
@@ -48,7 +48,7 @@ function TextareaWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
48
48
  onBlur={handleBlur}
49
49
  onFocus={handleFocus}
50
50
  onChange={handleChange}
51
- aria-describedby={ariaDescribedByIds<T>(id)}
51
+ aria-describedby={ariaDescribedByIds(id)}
52
52
  />
53
53
  );
54
54
  }
@@ -1,4 +1,12 @@
1
- import { englishStringTranslator, FormContextType, Registry, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
1
+ import {
2
+ DEFAULT_ID_PREFIX,
3
+ DEFAULT_ID_SEPARATOR,
4
+ englishStringTranslator,
5
+ FormContextType,
6
+ Registry,
7
+ RJSFSchema,
8
+ StrictRJSFSchema,
9
+ } from '@rjsf/utils';
2
10
 
3
11
  import fields from './components/fields';
4
12
  import templates from './components/templates';
@@ -20,5 +28,6 @@ export default function getDefaultRegistry<
20
28
  rootSchema: {} as S,
21
29
  formContext: {} as F,
22
30
  translateString: englishStringTranslator,
31
+ globalFormOptions: { idPrefix: DEFAULT_ID_PREFIX, idSeparator: DEFAULT_ID_SEPARATOR },
23
32
  };
24
33
  }
@@ -0,0 +1,34 @@
1
+ import {
2
+ DEFAULT_ID_PREFIX,
3
+ DEFAULT_ID_SEPARATOR,
4
+ createSchemaUtils,
5
+ englishStringTranslator,
6
+ Registry,
7
+ } from '@rjsf/utils';
8
+ import validator from '@rjsf/validator-ajv8';
9
+
10
+ import getDefaultRegistry from './getDefaultRegistry';
11
+
12
+ /** Use for react testing library tests where we directly test the component rather than testing inside a Form
13
+ */
14
+ export default function getTestRegistry(
15
+ rootSchema: Registry['rootSchema'],
16
+ fields: Registry['fields'] = {},
17
+ templates: Partial<Registry['templates']> = {},
18
+ widgets: Registry['widgets'] = {},
19
+ formContext: Registry['formContext'] = {},
20
+ globalFormOptions: Registry['globalFormOptions'] = { idPrefix: DEFAULT_ID_PREFIX, idSeparator: DEFAULT_ID_SEPARATOR },
21
+ ): Registry {
22
+ const defaults = getDefaultRegistry();
23
+ const schemaUtils = createSchemaUtils(validator, rootSchema);
24
+ return {
25
+ fields: { ...defaults.fields, ...fields },
26
+ templates: { ...defaults.templates, ...templates },
27
+ widgets: { ...defaults.widgets, ...widgets },
28
+ formContext,
29
+ rootSchema,
30
+ schemaUtils,
31
+ translateString: englishStringTranslator,
32
+ globalFormOptions,
33
+ };
34
+ }
package/src/index.ts CHANGED
@@ -2,8 +2,9 @@ import Form, { FormProps, FormState, IChangeEvent } from './components/Form';
2
2
  import RichDescription, { RichDescriptionProps } from './components/RichDescription';
3
3
  import withTheme, { ThemeProps } from './withTheme';
4
4
  import getDefaultRegistry from './getDefaultRegistry';
5
+ import getTestRegistry from './getTestRegistry';
5
6
 
6
7
  export type { FormProps, FormState, IChangeEvent, ThemeProps, RichDescriptionProps };
7
8
 
8
- export { withTheme, getDefaultRegistry, RichDescription };
9
+ export { withTheme, getDefaultRegistry, getTestRegistry, RichDescription };
9
10
  export default Form;