@rjsf/primereact 6.1.2 → 6.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjsf/primereact",
3
- "version": "6.1.2",
3
+ "version": "6.2.4",
4
4
  "description": "PrimeReact theme, fields and widgets for react-jsonschema-form",
5
5
  "main": "dist/index.js",
6
6
  "module": "lib/index.js",
@@ -61,17 +61,17 @@
61
61
  "node": ">=20"
62
62
  },
63
63
  "peerDependencies": {
64
- "@rjsf/core": "^6.x",
65
- "@rjsf/utils": "^6.x",
64
+ "@rjsf/core": "^6.2.x",
65
+ "@rjsf/utils": "^6.2.x",
66
66
  "primeicons": ">=6.0.0",
67
67
  "primereact": ">=8.0.0",
68
68
  "react": ">=18"
69
69
  },
70
70
  "devDependencies": {
71
- "@rjsf/core": "^6.x",
72
- "@rjsf/snapshot-tests": "^6.x",
73
- "@rjsf/utils": "^6.x",
74
- "@rjsf/validator-ajv8": "^6.x",
71
+ "@rjsf/core": "^6.2.0",
72
+ "@rjsf/snapshot-tests": "^6.2.0",
73
+ "@rjsf/utils": "^6.2.0",
74
+ "@rjsf/validator-ajv8": "^6.2.0",
75
75
  "@rollup/plugin-replace": "^6.0.3",
76
76
  "eslint": "^8.57.1",
77
77
  "primeflex": "^4.0.0",
@@ -34,6 +34,9 @@ export default function ArrayFieldTemplate<
34
34
  title,
35
35
  registry,
36
36
  required,
37
+ // Destructure the following props out so that they aren't put into the DOM
38
+ formData,
39
+ rawErrors,
37
40
  ...rest
38
41
  } = props;
39
42
 
@@ -1,4 +1,4 @@
1
- import { ChangeEvent } from 'react';
1
+ import { ChangeEvent, MouseEvent, useCallback } from 'react';
2
2
  import {
3
3
  ariaDescribedByIds,
4
4
  BaseInputTemplateProps,
@@ -37,36 +37,50 @@ export default function BaseInputTemplate<
37
37
  rawErrors = [],
38
38
  } = props;
39
39
 
40
+ const { ClearButton } = registry.templates.ButtonTemplates;
40
41
  const { AutoCompleteWidget } = registry.widgets;
41
42
 
42
- if (Array.isArray(schema.examples)) {
43
- return <AutoCompleteWidget {...props} />;
44
- }
45
-
46
43
  const inputProps = getInputProps<T, S, F>(schema, type, options);
47
44
  const primeProps = (options.prime || {}) as object;
48
45
  const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
49
46
  onChange(value === '' ? options.emptyValue : value);
50
47
  const _onBlur = () => onBlur && onBlur(id, value);
51
48
  const _onFocus = () => onFocus && onFocus(id, value);
49
+ const _onClear = useCallback(
50
+ (e: MouseEvent) => {
51
+ e.preventDefault();
52
+ e.stopPropagation();
53
+ onChange(options.emptyValue ?? '');
54
+ },
55
+ [onChange, options.emptyValue],
56
+ );
57
+
58
+ if (Array.isArray(schema.examples)) {
59
+ return <AutoCompleteWidget {...props} />;
60
+ }
52
61
 
53
62
  return (
54
- <InputText
55
- id={id}
56
- name={htmlName || id}
57
- placeholder={placeholder}
58
- {...primeProps}
59
- {...inputProps}
60
- required={required}
61
- autoFocus={autofocus}
62
- disabled={disabled || readonly}
63
- list={schema.examples ? examplesId(id) : undefined}
64
- value={value || value === 0 ? value : ''}
65
- invalid={rawErrors.length > 0}
66
- onChange={onChangeOverride || _onChange}
67
- onBlur={_onBlur}
68
- onFocus={_onFocus}
69
- aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
70
- />
63
+ <>
64
+ <InputText
65
+ id={id}
66
+ name={htmlName || id}
67
+ placeholder={placeholder}
68
+ {...primeProps}
69
+ {...inputProps}
70
+ required={required}
71
+ autoFocus={autofocus}
72
+ disabled={disabled || readonly}
73
+ list={schema.examples ? examplesId(id) : undefined}
74
+ value={value || value === 0 ? value : ''}
75
+ invalid={rawErrors.length > 0}
76
+ onChange={onChangeOverride || _onChange}
77
+ onBlur={_onBlur}
78
+ onFocus={_onFocus}
79
+ aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
80
+ />
81
+ {options.allowClearTextInputs && !readonly && !disabled && value && (
82
+ <ClearButton registry={registry} onClick={_onClear} />
83
+ )}
84
+ </>
71
85
  );
72
86
  }
@@ -49,3 +49,12 @@ export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F
49
49
  } = props;
50
50
  return <IconButton title={translateString(TranslatableString.RemoveButton)} {...props} icon='trash' />;
51
51
  }
52
+
53
+ export function ClearButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
54
+ props: PrimeIconButtonProps<T, S, F>,
55
+ ) {
56
+ const {
57
+ registry: { translateString },
58
+ } = props;
59
+ return <IconButton title={translateString(TranslatableString.ClearButton)} {...props} icon='times' />;
60
+ }
@@ -6,7 +6,7 @@ import ArrayFieldTemplate from '../ArrayFieldTemplate';
6
6
  import BaseInputTemplate from '../BaseInputTemplate';
7
7
  import DescriptionField from '../DescriptionField';
8
8
  import ErrorList from '../ErrorList';
9
- import { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } from '../IconButton';
9
+ import { CopyButton, MoveDownButton, MoveUpButton, RemoveButton, ClearButton } from '../IconButton';
10
10
  import FieldErrorTemplate from '../FieldErrorTemplate';
11
11
  import FieldHelpTemplate from '../FieldHelpTemplate';
12
12
  import FieldTemplate from '../FieldTemplate';
@@ -36,6 +36,7 @@ export function generateTemplates<
36
36
  MoveUpButton,
37
37
  RemoveButton,
38
38
  SubmitButton,
39
+ ClearButton,
39
40
  },
40
41
  DescriptionFieldTemplate: DescriptionField,
41
42
  ErrorListTemplate: ErrorList,