Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/list.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1139,4 +1139,36 @@ describe('Form.List', () => {
{ list: [{ name: 'John', tags: ['react', 'ts', 'redux'] }] },
);
});

it('should not drop list items when updating list item field', async () => {
const onValuesChange = jest.fn();

const { getAllByRole } = render(
<Form onValuesChange={onValuesChange}>
<Form.List
name="list"
initialValue={[{ name: 'A' }, { name: 'B' }, { name: 'C' }, { name: 'D' }]}
>
{fields =>
fields.map(field => (
<Field key={field.key} name={[field.name, 'name']}>
<input />
</Field>
))
}
</Form.List>
</Form>,
);

// Change second item (index = 1)
fireEvent.change(getAllByRole('textbox')[1], {
target: { value: 'BB' },
});

const [, allValues] = onValuesChange.mock.calls.pop();

expect(allValues).toEqual({
list: [{ name: 'A' }, { name: 'BB' }, { name: 'C' }, { name: 'D' }],
});
});
});