Browse Source
fix: Upload with maxCount not trigger onChange (#43193)
* test: test driven
* fix: Upload maxCount not trigger onChange
pull/43201/head
二货爱吃白萝卜
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
39 additions and
1 deletions
-
components/upload/Upload.tsx
-
components/upload/__tests__/upload.test.tsx
-
scripts/post-script.js
|
|
@ -113,7 +113,7 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = ( |
|
|
|
if (maxCount === 1) { |
|
|
|
cloneList = cloneList.slice(-1); |
|
|
|
} else if (maxCount) { |
|
|
|
exceedMaxCount = true; |
|
|
|
exceedMaxCount = cloneList.length > maxCount; |
|
|
|
cloneList = cloneList.slice(0, maxCount); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -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( |
|
|
|
<Upload |
|
|
|
onChange={onChange} |
|
|
|
maxCount={2} |
|
|
|
defaultFileList={[ |
|
|
|
{ |
|
|
|
uid: 'bamboo', |
|
|
|
name: 'bamboo.png', |
|
|
|
}, |
|
|
|
{ |
|
|
|
uid: 'little', |
|
|
|
name: 'little.png', |
|
|
|
}, |
|
|
|
]} |
|
|
|
showUploadList |
|
|
|
> |
|
|
|
<button type="button">upload</button> |
|
|
|
</Upload>, |
|
|
|
); |
|
|
|
|
|
|
|
// 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', () => { |
|
|
|
|
|
@ -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) { |
|
|
|