Skip to content

Commit 31ef0b7

Browse files
authored
fix(Form): avoid merging sparse list patches into allValue (#771)
* fix(Form): avoid merging sparse list patches into allValue * revert: drop mergeWith changes in useForm (not root cause) * chore(deps): bump @rc-component/util from 1.5.0 to 1.6.2
1 parent d2ac4b8 commit 31ef0b7

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
},
5151
"dependencies": {
5252
"@rc-component/async-validator": "^5.0.3",
53-
"@rc-component/util": "^1.5.0",
53+
"@rc-component/util": "^1.6.2",
5454
"clsx": "^2.1.1"
5555
},
5656
"devDependencies": {

tests/list.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,4 +1139,36 @@ describe('Form.List', () => {
11391139
{ list: [{ name: 'John', tags: ['react', 'ts', 'redux'] }] },
11401140
);
11411141
});
1142+
1143+
it('should not drop list items when updating list item field', async () => {
1144+
const onValuesChange = jest.fn();
1145+
1146+
const { getAllByRole } = render(
1147+
<Form onValuesChange={onValuesChange}>
1148+
<Form.List
1149+
name="list"
1150+
initialValue={[{ name: 'A' }, { name: 'B' }, { name: 'C' }, { name: 'D' }]}
1151+
>
1152+
{fields =>
1153+
fields.map(field => (
1154+
<Field key={field.key} name={[field.name, 'name']}>
1155+
<input />
1156+
</Field>
1157+
))
1158+
}
1159+
</Form.List>
1160+
</Form>,
1161+
);
1162+
1163+
// Change second item (index = 1)
1164+
fireEvent.change(getAllByRole('textbox')[1], {
1165+
target: { value: 'BB' },
1166+
});
1167+
1168+
const [, allValues] = onValuesChange.mock.calls.pop();
1169+
1170+
expect(allValues).toEqual({
1171+
list: [{ name: 'A' }, { name: 'BB' }, { name: 'C' }, { name: 'D' }],
1172+
});
1173+
});
11421174
});

0 commit comments

Comments
 (0)