mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-12 12:23:08 +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 cloneList = [...changedFileList];
|
||||||
|
|
||||||
|
let exceedMaxCount = false;
|
||||||
|
|
||||||
// Cut to match count
|
// Cut to match count
|
||||||
if (maxCount === 1) {
|
if (maxCount === 1) {
|
||||||
cloneList = cloneList.slice(-1);
|
cloneList = cloneList.slice(-1);
|
||||||
} else if (maxCount) {
|
} else if (maxCount) {
|
||||||
|
exceedMaxCount = true;
|
||||||
cloneList = cloneList.slice(0, maxCount);
|
cloneList = cloneList.slice(0, maxCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,9 +132,15 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
|
|||||||
changeInfo.event = event;
|
changeInfo.event = event;
|
||||||
}
|
}
|
||||||
|
|
||||||
flushSync(() => {
|
if (
|
||||||
onChange?.(changeInfo);
|
!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[]) => {
|
const mergedBeforeUpload = async (file: RcFile, fileListArgs: RcFile[]) => {
|
||||||
|
@ -480,7 +480,7 @@ describe('Upload', () => {
|
|||||||
// Delay return true for remove
|
// Delay return true for remove
|
||||||
await waitFakeTimer();
|
await waitFakeTimer();
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
await removePromise(true);
|
removePromise(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(onChange).toHaveBeenCalled();
|
expect(onChange).toHaveBeenCalled();
|
||||||
@ -771,6 +771,11 @@ describe('Upload', () => {
|
|||||||
name: 'foo.png',
|
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