fix: Upload should show remove icon when showRemoveIcon is true (#45752)

This commit is contained in:
afc163 2023-11-09 16:44:50 +08:00 committed by GitHub
parent 5261f1e365
commit c2ef52b9ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -376,6 +376,10 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
downloadIcon,
} = typeof showUploadList === 'boolean' ? ({} as ShowUploadListInterface) : showUploadList;
// use showRemoveIcon if it is specified explicitly
const realShowRemoveIcon =
typeof showRemoveIcon === 'undefined' ? !mergedDisabled : !!showRemoveIcon;
const renderUploadList = (button?: React.ReactNode, buttonVisible?: boolean) => {
if (!showUploadList) {
return button;
@ -389,7 +393,7 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
onPreview={onPreview}
onDownload={onDownload}
onRemove={handleRemove}
showRemoveIcon={!mergedDisabled && showRemoveIcon}
showRemoveIcon={realShowRemoveIcon}
showPreviewIcon={showPreviewIcon}
showDownloadIcon={showDownloadIcon}
removeIcon={removeIcon}

View File

@ -579,6 +579,34 @@ describe('Upload List', () => {
unmount();
});
// https://github.com/ant-design/ant-design/issues/27519
// https://github.com/ant-design/ant-design/issues/45735
it('should show remove icon when showRemoveIcon is true', () => {
const list = [
{
name: 'image',
status: 'uploading',
uid: '-4',
url: 'https://cdn.xxx.com/aaa',
},
];
const { container: wrapper, unmount } = render(
<Upload
listType="picture"
defaultFileList={list as UploadProps['defaultFileList']}
showUploadList={{
showRemoveIcon: true,
}}
disabled
>
<button type="button">upload</button>
</Upload>,
);
expect(wrapper.querySelector('.anticon-delete')).toBeTruthy();
unmount();
});
it('should support custom onClick in custom icon', async () => {
const handleRemove = jest.fn();
const handleChange = jest.fn();