mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 11:10:01 +08:00
fix: Upload with maxCount not trigger onChange (#43193)
* test: test driven * fix: Upload maxCount not trigger onChange
This commit is contained in:
parent
643a94afbe
commit
1765c49cdc
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user