From 334323651dca84fd95957aac26af798b25dedc22 Mon Sep 17 00:00:00 2001 From: Zhou Bill <735051883@qq.com> Date: Thu, 28 Mar 2024 10:14:34 +0800 Subject: [PATCH] fix: upload default FileList is more than maxCount, it can't remove it (#47747) * fix: upload default FileList is more than maxCount, it can't remove it * fix: snapshot * fix: line --- components/upload/Upload.tsx | 1 + components/upload/__tests__/upload.test.tsx | 47 +++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/components/upload/Upload.tsx b/components/upload/Upload.tsx index aa9a375953ae..9eaa2b87cd69 100644 --- a/components/upload/Upload.tsx +++ b/components/upload/Upload.tsx @@ -137,6 +137,7 @@ const InternalUpload: React.ForwardRefRenderFunction = ( if ( !exceedMaxCount || + file.status === 'removed' || // We should ignore event if current file is exceed `maxCount` cloneList.some((f) => f.uid === file.uid) ) { diff --git a/components/upload/__tests__/upload.test.tsx b/components/upload/__tests__/upload.test.tsx index 6e1d790dd568..9841b171ae6b 100644 --- a/components/upload/__tests__/upload.test.tsx +++ b/components/upload/__tests__/upload.test.tsx @@ -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( + + + , + ); + + 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', () => {