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
parent
commit
1765c49cdc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      components/upload/Upload.tsx
  2. 37
      components/upload/__tests__/upload.test.tsx
  3. 1
      scripts/post-script.js

2
components/upload/Upload.tsx

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

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

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

Loading…
Cancel
Save