From 1765c49cdceb1897d848fa9e260e4e683fcf2b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Mon, 26 Jun 2023 19:09:17 +0800 Subject: [PATCH] fix: Upload with maxCount not trigger onChange (#43193) * test: test driven * fix: Upload maxCount not trigger onChange --- components/upload/Upload.tsx | 2 +- components/upload/__tests__/upload.test.tsx | 37 +++++++++++++++++++++ scripts/post-script.js | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/components/upload/Upload.tsx b/components/upload/Upload.tsx index 1424c3f5ac..06fcb469f3 100644 --- a/components/upload/Upload.tsx +++ b/components/upload/Upload.tsx @@ -113,7 +113,7 @@ const InternalUpload: React.ForwardRefRenderFunction = ( if (maxCount === 1) { cloneList = cloneList.slice(-1); } else if (maxCount) { - exceedMaxCount = true; + exceedMaxCount = cloneList.length > maxCount; cloneList = cloneList.slice(0, maxCount); } diff --git a/components/upload/__tests__/upload.test.tsx b/components/upload/__tests__/upload.test.tsx index a733c80971..891c899c11 100644 --- a/components/upload/__tests__/upload.test.tsx +++ b/components/upload/__tests__/upload.test.tsx @@ -777,6 +777,43 @@ describe('Upload', () => { expect(args[0].file.name).toBe('foo.png'); }); }); + + // https://github.com/ant-design/ant-design/issues/43190 + it('should trigger onChange when remove', async () => { + const onChange = jest.fn(); + + const { container } = render( + + + , + ); + + // Click delete + fireEvent.click(container.querySelector('.ant-upload-list-item-action')!); + + await waitFakeTimer(); + + expect(onChange).toHaveBeenCalledWith( + expect.objectContaining({ + // Have 1 file + fileList: [expect.anything()], + }), + ); + }); }); it('auto fill file uid', () => { diff --git a/scripts/post-script.js b/scripts/post-script.js index 831ebae788..5972f434cb 100644 --- a/scripts/post-script.js +++ b/scripts/post-script.js @@ -38,6 +38,7 @@ const DEPRECIATED_VERSION = { 'https://github.com/ant-design/ant-design/pull/41993', ], '5.6.2': ['https://github.com/ant-design/ant-design/issues/43113'], + '5.6.3': ['https://github.com/ant-design/ant-design/issues/43190'], }; function matchDeprecated(version) {