mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 16:06:28 +08:00
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
This commit is contained in:
parent
7ec6a7b430
commit
7c09fc01ad
@ -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)
|
||||
) {
|
||||
|
@ -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', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user