Skip to content

Commit 7c09fc0

Browse files
authored
fix: upload default FileList is more than maxCount, it can't remove it (ant-design#47747)
* fix: upload default FileList is more than maxCount, it can't remove it * fix: snapshot * fix: line
1 parent 7ec6a7b commit 7c09fc0

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

components/upload/Upload.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
137137

138138
if (
139139
!exceedMaxCount ||
140+
file.status === 'removed' ||
140141
// We should ignore event if current file is exceed `maxCount`
141142
cloneList.some((f) => f.uid === file.uid)
142143
) {

components/upload/__tests__/upload.test.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,53 @@ describe('Upload', () => {
815815
}),
816816
);
817817
});
818+
819+
it('should trigger onChange when defaultFileList.length is longer than maxCount ', async () => {
820+
const onChange = jest.fn();
821+
822+
const { container } = render(
823+
<Upload
824+
onChange={onChange}
825+
maxCount={3}
826+
defaultFileList={[
827+
{
828+
uid: 'bamboo',
829+
name: 'bamboo.png',
830+
},
831+
{
832+
uid: 'little',
833+
name: 'little.png',
834+
},
835+
{
836+
uid: 'foo',
837+
name: 'foo.png',
838+
},
839+
{
840+
uid: 'bar',
841+
name: 'bar.png',
842+
},
843+
{
844+
uid: 'bar1',
845+
name: 'bar1.png',
846+
},
847+
]}
848+
showUploadList
849+
>
850+
<button type="button">upload</button>
851+
</Upload>,
852+
);
853+
854+
fireEvent.click(container.querySelector('.ant-upload-list-item-action')!);
855+
await waitFakeTimer();
856+
// Click delete
857+
858+
expect(onChange).toHaveBeenCalledWith(
859+
expect.objectContaining({
860+
// Have 3 file
861+
fileList: [expect.anything(), expect.anything(), expect.anything()],
862+
}),
863+
);
864+
});
818865
});
819866

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

0 commit comments

Comments
 (0)