fix: Upload with maxCount not trigger onChange (#43193)

* test: test driven

* fix: Upload maxCount not trigger onChange
This commit is contained in:
二货爱吃白萝卜 2023-06-26 19:09:17 +08:00 committed by GitHub
parent 643a94afbe
commit 1765c49cdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 1 deletions

View File

@ -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);
}

View File

@ -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', () => {

View File

@ -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) {