@canlooks/can-ui 0.0.56 → 0.0.57
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/dist/cjs/components/form/form.js +1 -0
- package/dist/cjs/components/form/formItem.d.ts +5 -2
- package/dist/cjs/components/form/formItem.js +2 -3
- package/dist/esm/components/form/form.js +1 -0
- package/dist/esm/components/form/formItem.d.ts +5 -2
- package/dist/esm/components/form/formItem.js +2 -3
- package/package.json +1 -1
|
@@ -10,7 +10,6 @@ export type FormItemRules<I = any> = {
|
|
|
10
10
|
validator?(fieldValue: I | undefined, formValue: any, formRef: FormRef | null): any;
|
|
11
11
|
};
|
|
12
12
|
export type FieldProps<I = any> = {
|
|
13
|
-
key?: string;
|
|
14
13
|
checked?: boolean;
|
|
15
14
|
value?: I;
|
|
16
15
|
onChange?(e: any): void;
|
|
@@ -29,7 +28,11 @@ export interface FormItemOwnProps<I = any> extends FormSharedProps {
|
|
|
29
28
|
error?: boolean;
|
|
30
29
|
helperText?: ReactNode;
|
|
31
30
|
dependencies?: FieldPath[];
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* 若`children`为`function`类型时,第三个参数`key`主要用于强制重渲染,
|
|
33
|
+
* 在没有{@link initialValue}时非常有用
|
|
34
|
+
*/
|
|
35
|
+
children?: ReactNode | ((fieldProps: FieldProps<I>, styleProps: StyleProps, key?: string) => ReactNode);
|
|
33
36
|
noStyle?: boolean;
|
|
34
37
|
}
|
|
35
38
|
export type FormItemProps<I = any, C extends ElementType = 'div'> = MergeProps<FormItemOwnProps<I>, DescriptionItemProps<C>>;
|
|
@@ -89,7 +89,7 @@ const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, req
|
|
|
89
89
|
// formRef的resetForm()方法会传入新的initialValue,否则使用`formValue`
|
|
90
90
|
const reset = (value = formValue) => {
|
|
91
91
|
shouldValidate.current = isTouched.current = false;
|
|
92
|
-
if (typeof field !== 'undefined' && value) {
|
|
92
|
+
if (typeof field !== 'undefined' && value && typeof initialValue !== 'undefined') {
|
|
93
93
|
(0, utils_1.queryDeep)(value, field, () => initialValue);
|
|
94
94
|
}
|
|
95
95
|
innerError.current && setInnerError(false);
|
|
@@ -128,7 +128,6 @@ const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, req
|
|
|
128
128
|
if (typeof children === 'function') {
|
|
129
129
|
return children(typeof field !== 'undefined'
|
|
130
130
|
? {
|
|
131
|
-
key: randomKey.current,
|
|
132
131
|
...typeof fieldValue === 'boolean'
|
|
133
132
|
? { checked: fieldValue }
|
|
134
133
|
: { value: fieldValue },
|
|
@@ -140,7 +139,7 @@ const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, req
|
|
|
140
139
|
: {}, {
|
|
141
140
|
...props.size && { size: props.size },
|
|
142
141
|
...innerError.current ? { color: 'error' } : {}
|
|
143
|
-
});
|
|
142
|
+
}, randomKey.current);
|
|
144
143
|
}
|
|
145
144
|
if ((0, react_1.isValidElement)(children)) {
|
|
146
145
|
const { props: childProps } = children;
|
|
@@ -10,7 +10,6 @@ export type FormItemRules<I = any> = {
|
|
|
10
10
|
validator?(fieldValue: I | undefined, formValue: any, formRef: FormRef | null): any;
|
|
11
11
|
};
|
|
12
12
|
export type FieldProps<I = any> = {
|
|
13
|
-
key?: string;
|
|
14
13
|
checked?: boolean;
|
|
15
14
|
value?: I;
|
|
16
15
|
onChange?(e: any): void;
|
|
@@ -29,7 +28,11 @@ export interface FormItemOwnProps<I = any> extends FormSharedProps {
|
|
|
29
28
|
error?: boolean;
|
|
30
29
|
helperText?: ReactNode;
|
|
31
30
|
dependencies?: FieldPath[];
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* 若`children`为`function`类型时,第三个参数`key`主要用于强制重渲染,
|
|
33
|
+
* 在没有{@link initialValue}时非常有用
|
|
34
|
+
*/
|
|
35
|
+
children?: ReactNode | ((fieldProps: FieldProps<I>, styleProps: StyleProps, key?: string) => ReactNode);
|
|
33
36
|
noStyle?: boolean;
|
|
34
37
|
}
|
|
35
38
|
export type FormItemProps<I = any, C extends ElementType = 'div'> = MergeProps<FormItemOwnProps<I>, DescriptionItemProps<C>>;
|
|
@@ -86,7 +86,7 @@ export const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rul
|
|
|
86
86
|
// formRef的resetForm()方法会传入新的initialValue,否则使用`formValue`
|
|
87
87
|
const reset = (value = formValue) => {
|
|
88
88
|
shouldValidate.current = isTouched.current = false;
|
|
89
|
-
if (typeof field !== 'undefined' && value) {
|
|
89
|
+
if (typeof field !== 'undefined' && value && typeof initialValue !== 'undefined') {
|
|
90
90
|
queryDeep(value, field, () => initialValue);
|
|
91
91
|
}
|
|
92
92
|
innerError.current && setInnerError(false);
|
|
@@ -125,7 +125,6 @@ export const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rul
|
|
|
125
125
|
if (typeof children === 'function') {
|
|
126
126
|
return children(typeof field !== 'undefined'
|
|
127
127
|
? {
|
|
128
|
-
key: randomKey.current,
|
|
129
128
|
...typeof fieldValue === 'boolean'
|
|
130
129
|
? { checked: fieldValue }
|
|
131
130
|
: { value: fieldValue },
|
|
@@ -137,7 +136,7 @@ export const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rul
|
|
|
137
136
|
: {}, {
|
|
138
137
|
...props.size && { size: props.size },
|
|
139
138
|
...innerError.current ? { color: 'error' } : {}
|
|
140
|
-
});
|
|
139
|
+
}, randomKey.current);
|
|
141
140
|
}
|
|
142
141
|
if (isValidElement(children)) {
|
|
143
142
|
const { props: childProps } = children;
|