rsuite 5.9.0 → 5.10.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/CHANGELOG.md +6 -0
- package/cjs/Form/Form.d.ts +1 -1
- package/cjs/Form/Form.js +15 -5
- package/cjs/Form/FormContext.d.ts +2 -0
- package/cjs/FormControl/FormControl.d.ts +2 -0
- package/cjs/FormControl/FormControl.js +11 -1
- package/dist/rsuite.js +2 -2
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/Form/Form.d.ts +1 -1
- package/esm/Form/Form.js +15 -5
- package/esm/Form/FormContext.d.ts +2 -0
- package/esm/FormControl/FormControl.d.ts +2 -0
- package/esm/FormControl/FormControl.js +12 -1
- package/package.json +1 -1
package/esm/Form/Form.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface FormProps<T = Record<string, any>, errorMsgType = any, E = {
|
|
|
33
33
|
/** The error message comes from context */
|
|
34
34
|
errorFromContext?: boolean;
|
|
35
35
|
/** Callback fired when data changing */
|
|
36
|
-
onChange?: (formValue: T, event
|
|
36
|
+
onChange?: (formValue: T, event?: React.SyntheticEvent) => void;
|
|
37
37
|
/** Callback fired when error checking */
|
|
38
38
|
onError?: (formError: E) => void;
|
|
39
39
|
/** Callback fired when data cheking */
|
package/esm/Form/Form.js
CHANGED
|
@@ -199,6 +199,16 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
199
199
|
resetErrors: resetErrors
|
|
200
200
|
};
|
|
201
201
|
});
|
|
202
|
+
var removeFieldError = useCallback(function (name) {
|
|
203
|
+
var formError = omit(getFormError(), [name]);
|
|
204
|
+
setFormError(formError);
|
|
205
|
+
onCheck === null || onCheck === void 0 ? void 0 : onCheck(formError);
|
|
206
|
+
}, [getFormError, onCheck]);
|
|
207
|
+
var removeFieldValue = useCallback(function (name) {
|
|
208
|
+
var formValue = omit(getFormValue(), [name]);
|
|
209
|
+
setFormValue(formValue);
|
|
210
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(formValue);
|
|
211
|
+
}, [getFormValue, onChange]);
|
|
202
212
|
var handleSubmit = useCallback(function (event) {
|
|
203
213
|
if (disabled || readOnly || plaintext) {
|
|
204
214
|
return;
|
|
@@ -219,10 +229,8 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
219
229
|
onCheck === null || onCheck === void 0 ? void 0 : onCheck(formError);
|
|
220
230
|
}, [onError, onCheck, getFormError]);
|
|
221
231
|
var handleFieldSuccess = useCallback(function (name) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
onCheck === null || onCheck === void 0 ? void 0 : onCheck(formError);
|
|
225
|
-
}, [onCheck, getFormError]);
|
|
232
|
+
removeFieldError(name);
|
|
233
|
+
}, [removeFieldError]);
|
|
226
234
|
var handleFieldChange = useCallback(function (name, value, event) {
|
|
227
235
|
var _extends5;
|
|
228
236
|
|
|
@@ -244,11 +252,13 @@ var Form = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
244
252
|
plaintext: plaintext,
|
|
245
253
|
disabled: disabled,
|
|
246
254
|
formError: getFormError(),
|
|
255
|
+
removeFieldValue: removeFieldValue,
|
|
256
|
+
removeFieldError: removeFieldError,
|
|
247
257
|
onFieldChange: handleFieldChange,
|
|
248
258
|
onFieldError: handleFieldError,
|
|
249
259
|
onFieldSuccess: handleFieldSuccess
|
|
250
260
|
};
|
|
251
|
-
}, [model, checkTrigger, formDefaultValue, errorFromContext, readOnly, plaintext, disabled, getFormError, handleFieldChange, handleFieldError, handleFieldSuccess]);
|
|
261
|
+
}, [model, checkTrigger, formDefaultValue, errorFromContext, readOnly, plaintext, disabled, getFormError, removeFieldValue, removeFieldError, handleFieldChange, handleFieldError, handleFieldSuccess]);
|
|
252
262
|
return /*#__PURE__*/React.createElement("form", _extends({}, rest, {
|
|
253
263
|
ref: rootRef,
|
|
254
264
|
onSubmit: handleSubmit,
|
|
@@ -12,6 +12,8 @@ export interface FormContextValue<T = Record<string, any>, errorMsgType = any, E
|
|
|
12
12
|
plaintext?: boolean;
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
formError?: E;
|
|
15
|
+
removeFieldValue?: (name: string) => void;
|
|
16
|
+
removeFieldError?: (name: string) => void;
|
|
15
17
|
onFieldChange?: (name: string, value: any, event: React.SyntheticEvent) => void;
|
|
16
18
|
onFieldError?: (name: string, errorMessage: string) => void;
|
|
17
19
|
onFieldSuccess?: (name: string) => void;
|
|
@@ -28,6 +28,8 @@ export interface FormControlProps<P = any, ValueType = any> extends WithAsProps,
|
|
|
28
28
|
disabled?: boolean;
|
|
29
29
|
/** Asynchronous check value */
|
|
30
30
|
checkAsync?: boolean;
|
|
31
|
+
/** Remove field value and error message when component is unmounted */
|
|
32
|
+
shouldResetWithUnmount?: boolean;
|
|
31
33
|
}
|
|
32
34
|
interface FormControlComponent extends React.FC<FormControlProps> {
|
|
33
35
|
<Accepter extends React.ElementType = typeof Input>(props: FormControlProps & {
|
|
@@ -12,6 +12,7 @@ import FormErrorMessage from '../FormErrorMessage';
|
|
|
12
12
|
import { useClassNames } from '../utils';
|
|
13
13
|
import FormContext, { FormValueContext } from '../Form/FormContext';
|
|
14
14
|
import { FormGroupContext } from '../FormGroup/FormGroup';
|
|
15
|
+
import { useWillUnmount } from '../utils';
|
|
15
16
|
/**
|
|
16
17
|
* Props that FormControl passes to its accepter
|
|
17
18
|
*/
|
|
@@ -25,6 +26,8 @@ var FormControl = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
25
26
|
_useContext$formDefau = _useContext.formDefaultValue,
|
|
26
27
|
formDefaultValue = _useContext$formDefau === void 0 ? {} : _useContext$formDefau,
|
|
27
28
|
formError = _useContext.formError,
|
|
29
|
+
removeFieldValue = _useContext.removeFieldValue,
|
|
30
|
+
removeFieldError = _useContext.removeFieldError,
|
|
28
31
|
onFieldChange = _useContext.onFieldChange,
|
|
29
32
|
onFieldError = _useContext.onFieldError,
|
|
30
33
|
onFieldSuccess = _useContext.onFieldSuccess,
|
|
@@ -54,7 +57,9 @@ var FormControl = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
54
57
|
onChange = props.onChange,
|
|
55
58
|
onBlur = props.onBlur,
|
|
56
59
|
defaultValue = props.defaultValue,
|
|
57
|
-
|
|
60
|
+
_props$shouldResetWit = props.shouldResetWithUnmount,
|
|
61
|
+
shouldResetWithUnmount = _props$shouldResetWit === void 0 ? false : _props$shouldResetWit,
|
|
62
|
+
rest = _objectWithoutPropertiesLoose(props, ["as", "accepter", "classPrefix", "className", "checkAsync", "checkTrigger", "errorPlacement", "errorMessage", "name", "value", "readOnly", "plaintext", "disabled", "onChange", "onBlur", "defaultValue", "shouldResetWithUnmount"]);
|
|
58
63
|
|
|
59
64
|
var _useContext2 = useContext(FormGroupContext),
|
|
60
65
|
controlId = _useContext2.controlId;
|
|
@@ -63,6 +68,12 @@ var FormControl = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
63
68
|
throw new Error("\n <FormControl> must be inside a component decorated with <Form>.\n And need to update React to 16.6.0 +.\n ");
|
|
64
69
|
}
|
|
65
70
|
|
|
71
|
+
useWillUnmount(function () {
|
|
72
|
+
if (shouldResetWithUnmount) {
|
|
73
|
+
removeFieldValue === null || removeFieldValue === void 0 ? void 0 : removeFieldValue(name);
|
|
74
|
+
removeFieldError === null || removeFieldError === void 0 ? void 0 : removeFieldError(name);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
66
77
|
var trigger = checkTrigger || contextCheckTrigger;
|
|
67
78
|
var formValue = useContext(FormValueContext);
|
|
68
79
|
var val = isUndefined(value) ? formValue === null || formValue === void 0 ? void 0 : formValue[name] : value;
|