Skip to content

Commit

Permalink
fix(Upload): fix manual uploadFilePercent not update display (#2901)
Browse files Browse the repository at this point in the history
Co-authored-by: Heising <[email protected]>
  • Loading branch information
HaixingOoO and Heising authored May 15, 2024
1 parent 348aa61 commit 2d24c50
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/upload/hooks/useUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function useUpload(props: TdUploadProps) {
const xhrReq = useRef<{ files: UploadFile[]; xhrReq: XMLHttpRequest }[]>([]);
const [toUploadFiles, setToUploadFiles] = useState<UploadFile[]>([]);
const [sizeOverLimitMessage, setSizeOverLimitMessage] = useState('');
const [update, forceUpdate] = useState({});

const locale = useMemo(() => merge({}, globalLocale, props.locale), [globalLocale, props.locale]);

Expand Down Expand Up @@ -59,7 +60,7 @@ export default function useUpload(props: TdUploadProps) {
isBatchUpload,
});
setDisplayFiles(files);
}, [props.multiple, toUploadFiles, uploadValue, autoUpload, isBatchUpload]);
}, [props.multiple, toUploadFiles, uploadValue, autoUpload, isBatchUpload, update]);

const uploadFilePercent = (params: { file: UploadFile; percent: number }) => {
const { file, percent } = params;
Expand All @@ -71,6 +72,11 @@ export default function useUpload(props: TdUploadProps) {
} else {
const index = uploadValue.findIndex((item) => file.raw === item.raw);
uploadValue[index] = { ...uploadValue[index], percent };
/**
* 使用强制更新,修复手动自定义上传的percent无效
* https://github.com/Tencent/tdesign-react/issues/2893
*/
forceUpdate({});
}
};

Expand Down

0 comments on commit 2d24c50

Please sign in to comment.