File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,9 @@ export interface ListProps {
29
29
operations : ListOperations ,
30
30
meta : Meta ,
31
31
) => JSX . Element | React . ReactNode ;
32
+
33
+ /** @private Passed by Form.List props. Do not use since it will break by path check. */
34
+ isListField ?: boolean ;
32
35
}
33
36
34
37
const List : React . FunctionComponent < ListProps > = ( {
@@ -37,6 +40,7 @@ const List: React.FunctionComponent<ListProps> = ({
37
40
children,
38
41
rules,
39
42
validateTrigger,
43
+ isListField,
40
44
} ) => {
41
45
const context = React . useContext ( FieldContext ) ;
42
46
const keyRef = React . useRef ( {
@@ -87,6 +91,7 @@ const List: React.FunctionComponent<ListProps> = ({
87
91
validateTrigger = { validateTrigger }
88
92
initialValue = { initialValue }
89
93
isList
94
+ isListField = { isListField }
90
95
>
91
96
{ ( { value = [ ] , onChange } , meta ) => {
92
97
const { getFieldValue } = context ;
Original file line number Diff line number Diff line change @@ -403,4 +403,46 @@ describe('Form.Preserve', () => {
403
403
404
404
expect ( container . querySelector < HTMLInputElement > ( 'input' ) ?. value ) . toEqual ( 'bamboo' ) ;
405
405
} ) ;
406
+
407
+ it ( 'nest Form.List should clear correctly' , async ( ) => {
408
+ const { container } = render (
409
+ < Form
410
+ preserve = { false }
411
+ initialValues = { {
412
+ parent : [ [ { name : 'bamboo' } ] ] ,
413
+ } }
414
+ >
415
+ < Form . List name = "parent" >
416
+ { ( fields , { remove } ) => {
417
+ return fields . map ( field => (
418
+ < div key = { field . key } >
419
+ < button
420
+ onClick = { ( ) => {
421
+ remove ( field . name ) ;
422
+ } }
423
+ />
424
+ < Form . List { ...field } name = { [ field . name ] } >
425
+ { childFields =>
426
+ childFields . map ( childField => (
427
+ < div key = { childField . key } >
428
+ < Form . Field { ...childField } name = { [ childField . name , 'name' ] } >
429
+ < input />
430
+ </ Form . Field >
431
+ </ div >
432
+ ) )
433
+ }
434
+ </ Form . List >
435
+ </ div >
436
+ ) ) ;
437
+ } }
438
+ </ Form . List >
439
+ </ Form > ,
440
+ ) ;
441
+
442
+ expect ( container . querySelector ( 'input' ) . value ) . toEqual ( 'bamboo' ) ;
443
+
444
+ // Clean
445
+ fireEvent . click ( container . querySelector ( 'button' ) ) ;
446
+ expect ( container . querySelector ( 'input' ) ) . toBeFalsy ( ) ;
447
+ } ) ;
406
448
} ) ;
You can’t perform that action at this time.
0 commit comments