Skip to content

Commit

Permalink
fix: upload default FileList is more than maxCount, it can't remove it (
Browse files Browse the repository at this point in the history
ant-design#47747)

* fix: upload default FileList is more than maxCount, it can't remove it

* fix: snapshot

* fix: line
  • Loading branch information
Zhou-Bill authored and tanzhenyun committed Mar 29, 2024
1 parent 3088e72 commit 7550663
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/upload/Upload.tsx
Expand Up @@ -137,6 +137,7 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (

if (
!exceedMaxCount ||
file.status === 'removed' ||
// We should ignore event if current file is exceed `maxCount`
cloneList.some((f) => f.uid === file.uid)
) {
Expand Down
47 changes: 47 additions & 0 deletions components/upload/__tests__/upload.test.tsx
Expand Up @@ -815,6 +815,53 @@ describe('Upload', () => {
}),
);
});

it('should trigger onChange when defaultFileList.length is longer than maxCount ', async () => {
const onChange = jest.fn();

const { container } = render(
<Upload
onChange={onChange}
maxCount={3}
defaultFileList={[
{
uid: 'bamboo',
name: 'bamboo.png',
},
{
uid: 'little',
name: 'little.png',
},
{
uid: 'foo',
name: 'foo.png',
},
{
uid: 'bar',
name: 'bar.png',
},
{
uid: 'bar1',
name: 'bar1.png',
},
]}
showUploadList
>
<button type="button">upload</button>
</Upload>,
);

fireEvent.click(container.querySelector('.ant-upload-list-item-action')!);
await waitFakeTimer();
// Click delete

expect(onChange).toHaveBeenCalledWith(
expect.objectContaining({
// Have 3 file
fileList: [expect.anything(), expect.anything(), expect.anything()],
}),
);
});
});

it('auto fill file uid', () => {
Expand Down

0 comments on commit 7550663

Please sign in to comment.