@rjsf/mui 6.1.2 → 6.2.3

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.1.2",
3
+ "version": "6.2.3",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -64,8 +64,8 @@
64
64
  "@emotion/styled": "^11.6.0",
65
65
  "@mui/icons-material": "^7.0.0",
66
66
  "@mui/material": "^7.0.0",
67
- "@rjsf/core": "^6.x",
68
- "@rjsf/utils": "^6.x",
67
+ "@rjsf/core": "^6.2.x",
68
+ "@rjsf/utils": "^6.2.x",
69
69
  "react": ">=18"
70
70
  },
71
71
  "devDependencies": {
@@ -74,10 +74,10 @@
74
74
  "@emotion/styled": "^11.14.1",
75
75
  "@mui/icons-material": "^7.3.4",
76
76
  "@mui/material": "^7.3.4",
77
- "@rjsf/core": "^6.x",
78
- "@rjsf/snapshot-tests": "^6.x",
79
- "@rjsf/utils": "^6.x",
80
- "@rjsf/validator-ajv8": "^6.x",
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",
81
81
  "eslint": "^8.57.1"
82
82
  },
83
83
  "publishConfig": {
@@ -1,5 +1,7 @@
1
- import { ChangeEvent, FocusEvent } from 'react';
1
+ import { ChangeEvent, FocusEvent, MouseEvent, useCallback } from 'react';
2
2
  import TextField, { TextFieldProps } from '@mui/material/TextField';
3
+ import InputAdornment from '@mui/material/InputAdornment';
4
+
3
5
  import {
4
6
  ariaDescribedByIds,
5
7
  BaseInputTemplateProps,
@@ -51,6 +53,7 @@ export default function BaseInputTemplate<
51
53
  InputLabelProps,
52
54
  ...textFieldProps
53
55
  } = props;
56
+ const { ClearButton } = registry.templates.ButtonTemplates;
54
57
  const inputProps = getInputProps<T, S, F>(schema, type, options);
55
58
  // Now we need to pull out the step, min, max into an inner `inputProps` for material-ui
56
59
  const { step, min, max, accept, ...rest } = inputProps;
@@ -65,6 +68,14 @@ export default function BaseInputTemplate<
65
68
  shrink: true,
66
69
  }
67
70
  : InputLabelProps;
71
+ const _onClear = useCallback(
72
+ (e: MouseEvent) => {
73
+ e.preventDefault();
74
+ e.stopPropagation();
75
+ onChange(options.emptyValue ?? '');
76
+ },
77
+ [onChange, options.emptyValue],
78
+ );
68
79
 
69
80
  return (
70
81
  <>
@@ -85,6 +96,15 @@ export default function BaseInputTemplate<
85
96
  onFocus={_onFocus}
86
97
  {...(textFieldProps as TextFieldProps)}
87
98
  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
+ }}
88
108
  />
89
109
  {Array.isArray(schema.examples) && (
90
110
  <datalist id={examplesId(id)}>
@@ -3,6 +3,7 @@ import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
3
3
  import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
4
4
  import CopyIcon from '@mui/icons-material/ContentCopy';
5
5
  import RemoveIcon from '@mui/icons-material/Remove';
6
+ import ClearIcon from '@mui/icons-material/Clear';
6
7
  import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils';
7
8
 
8
9
  export default function MuiIconButton<
@@ -79,3 +80,19 @@ export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F
79
80
  />
80
81
  );
81
82
  }
83
+
84
+ export function ClearButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
85
+ props: IconButtonProps<T, S, F>,
86
+ ) {
87
+ const { iconType, ...otherProps } = props;
88
+ const {
89
+ registry: { translateString },
90
+ } = otherProps;
91
+ return (
92
+ <MuiIconButton
93
+ title={translateString(TranslatableString.ClearButton)}
94
+ {...otherProps}
95
+ icon={<ClearIcon fontSize={iconType === 'default' ? undefined : 'small'} />}
96
+ />
97
+ );
98
+ }
@@ -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';
@@ -34,6 +34,7 @@ export function generateTemplates<
34
34
  MoveUpButton,
35
35
  RemoveButton,
36
36
  SubmitButton,
37
+ ClearButton,
37
38
  },
38
39
  DescriptionFieldTemplate: DescriptionField,
39
40
  ErrorListTemplate: ErrorList,