mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 06:03:38 +08:00
fix: upload event should not trigger the file out of maxCount (#43034)
* fix: upload event should not trigger the file out of maxCount * chore: opt match logic * chore: refactor use some
This commit is contained in:
parent
3c979eb84b
commit
b037433d2b
@ -107,10 +107,13 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
|
||||
) => {
|
||||
let cloneList = [...changedFileList];
|
||||
|
||||
let exceedMaxCount = false;
|
||||
|
||||
// Cut to match count
|
||||
if (maxCount === 1) {
|
||||
cloneList = cloneList.slice(-1);
|
||||
} else if (maxCount) {
|
||||
exceedMaxCount = true;
|
||||
cloneList = cloneList.slice(0, maxCount);
|
||||
}
|
||||
|
||||
@ -129,9 +132,15 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
|
||||
changeInfo.event = event;
|
||||
}
|
||||
|
||||
flushSync(() => {
|
||||
onChange?.(changeInfo);
|
||||
});
|
||||
if (
|
||||
!exceedMaxCount ||
|
||||
// We should ignore event if current file is exceed `maxCount`
|
||||
cloneList.some((f) => f.uid === file.uid)
|
||||
) {
|
||||
flushSync(() => {
|
||||
onChange?.(changeInfo);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const mergedBeforeUpload = async (file: RcFile, fileListArgs: RcFile[]) => {
|
||||
|
@ -480,7 +480,7 @@ describe('Upload', () => {
|
||||
// Delay return true for remove
|
||||
await waitFakeTimer();
|
||||
await act(async () => {
|
||||
await removePromise(true);
|
||||
removePromise(true);
|
||||
});
|
||||
|
||||
expect(onChange).toHaveBeenCalled();
|
||||
@ -771,6 +771,11 @@ describe('Upload', () => {
|
||||
name: 'foo.png',
|
||||
}),
|
||||
]);
|
||||
|
||||
// Only trigger for file in `maxCount`
|
||||
onChange.mock.calls.forEach((args) => {
|
||||
expect(args[0].file.name).toBe('foo.png');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user