@rjsf/mui 6.2.4 → 6.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjsf/mui",
3
- "version": "6.2.4",
3
+ "version": "6.3.0",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -69,15 +69,15 @@
69
69
  "react": ">=18"
70
70
  },
71
71
  "devDependencies": {
72
- "@emotion/jest": "^11.13.0",
72
+ "@emotion/jest": "^11.14.2",
73
73
  "@emotion/react": "^11.14.0",
74
74
  "@emotion/styled": "^11.14.1",
75
- "@mui/icons-material": "^7.3.4",
76
- "@mui/material": "^7.3.4",
77
- "@rjsf/core": "^6.2.0",
78
- "@rjsf/snapshot-tests": "^6.2.0",
79
- "@rjsf/utils": "^6.2.0",
80
- "@rjsf/validator-ajv8": "^6.2.0",
75
+ "@mui/icons-material": "^7.3.7",
76
+ "@mui/material": "^7.3.7",
77
+ "@rjsf/core": "^6.2.5",
78
+ "@rjsf/snapshot-tests": "^6.2.5",
79
+ "@rjsf/utils": "^6.2.5",
80
+ "@rjsf/validator-ajv8": "^6.2.5",
81
81
  "eslint": "^8.57.1"
82
82
  },
83
83
  "publishConfig": {
@@ -12,6 +12,7 @@ import {
12
12
  RJSFSchema,
13
13
  StrictRJSFSchema,
14
14
  } from '@rjsf/utils';
15
+ import { SchemaExamples } from '@rjsf/core';
15
16
 
16
17
  const TYPES_THAT_SHRINK_LABEL = ['date', 'datetime-local', 'file', 'time'];
17
18
 
@@ -51,23 +52,28 @@ export default function BaseInputTemplate<
51
52
  errorSchema,
52
53
  registry,
53
54
  InputLabelProps,
55
+ InputProps,
56
+ slotProps,
54
57
  ...textFieldProps
55
58
  } = props;
56
59
  const { ClearButton } = registry.templates.ButtonTemplates;
57
- const inputProps = getInputProps<T, S, F>(schema, type, options);
58
60
  // Now we need to pull out the step, min, max into an inner `inputProps` for material-ui
59
- const { step, min, max, accept, ...rest } = inputProps;
60
- const htmlInputProps = { step, min, max, accept, ...(schema.examples ? { list: examplesId(id) } : undefined) };
61
+ const { step, min, max, accept, ...rest } = getInputProps<T, S, F>(schema, type, options);
62
+ const htmlInputProps = {
63
+ ...slotProps?.htmlInput,
64
+ step,
65
+ min,
66
+ max,
67
+ accept,
68
+ ...(schema.examples ? { list: examplesId(id) } : undefined),
69
+ };
61
70
  const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
62
71
  onChange(value === '' ? options.emptyValue : value);
63
72
  const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.value);
64
73
  const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.value);
65
74
  const DisplayInputLabelProps = TYPES_THAT_SHRINK_LABEL.includes(type)
66
- ? {
67
- ...InputLabelProps,
68
- shrink: true,
69
- }
70
- : InputLabelProps;
75
+ ? { ...slotProps?.inputLabel, ...InputLabelProps, shrink: true }
76
+ : { ...slotProps?.inputLabel, ...InputLabelProps };
71
77
  const _onClear = useCallback(
72
78
  (e: MouseEvent) => {
73
79
  e.preventDefault();
@@ -76,6 +82,22 @@ export default function BaseInputTemplate<
76
82
  },
77
83
  [onChange, options.emptyValue],
78
84
  );
85
+ const inputProps = { ...InputProps, ...slotProps?.input };
86
+ if (options.allowClearTextInputs && value && !readonly && !disabled) {
87
+ const clearAdornment = (
88
+ <InputAdornment position='end'>
89
+ <ClearButton registry={registry} onClick={_onClear} />
90
+ </InputAdornment>
91
+ );
92
+ inputProps.endAdornment = !inputProps.endAdornment ? (
93
+ clearAdornment
94
+ ) : (
95
+ <>
96
+ {inputProps.endAdornment}
97
+ {clearAdornment}
98
+ </>
99
+ );
100
+ }
79
101
 
80
102
  return (
81
103
  <>
@@ -87,7 +109,12 @@ export default function BaseInputTemplate<
87
109
  autoFocus={autofocus}
88
110
  required={required}
89
111
  disabled={disabled || readonly}
90
- slotProps={{ htmlInput: htmlInputProps, inputLabel: DisplayInputLabelProps }}
112
+ slotProps={{
113
+ ...slotProps,
114
+ input: inputProps,
115
+ htmlInput: htmlInputProps,
116
+ inputLabel: DisplayInputLabelProps,
117
+ }}
91
118
  {...rest}
92
119
  value={value || value === 0 ? value : ''}
93
120
  error={rawErrors.length > 0}
@@ -96,25 +123,8 @@ export default function BaseInputTemplate<
96
123
  onFocus={_onFocus}
97
124
  {...(textFieldProps as TextFieldProps)}
98
125
  aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
99
- InputProps={{
100
- ...textFieldProps.InputProps,
101
- endAdornment:
102
- options.allowClearTextInputs && value && !readonly && !disabled ? (
103
- <InputAdornment position='end'>
104
- <ClearButton registry={registry} onClick={_onClear} />
105
- </InputAdornment>
106
- ) : undefined,
107
- }}
108
126
  />
109
- {Array.isArray(schema.examples) && (
110
- <datalist id={examplesId(id)}>
111
- {(schema.examples as string[])
112
- .concat(schema.default && !schema.examples.includes(schema.default) ? ([schema.default] as string[]) : [])
113
- .map((example: any) => {
114
- return <option key={example} value={example} />;
115
- })}
116
- </datalist>
117
- )}
127
+ <SchemaExamples id={id} schema={schema} />
118
128
  </>
119
129
  );
120
130
  }