mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 14:13:37 +08:00
fix: Upload should show remove icon when showRemoveIcon is true (#45752)
This commit is contained in:
parent
5261f1e365
commit
c2ef52b9ba
@ -376,6 +376,10 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
|
|||||||
downloadIcon,
|
downloadIcon,
|
||||||
} = typeof showUploadList === 'boolean' ? ({} as ShowUploadListInterface) : showUploadList;
|
} = 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) => {
|
const renderUploadList = (button?: React.ReactNode, buttonVisible?: boolean) => {
|
||||||
if (!showUploadList) {
|
if (!showUploadList) {
|
||||||
return button;
|
return button;
|
||||||
@ -389,7 +393,7 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
|
|||||||
onPreview={onPreview}
|
onPreview={onPreview}
|
||||||
onDownload={onDownload}
|
onDownload={onDownload}
|
||||||
onRemove={handleRemove}
|
onRemove={handleRemove}
|
||||||
showRemoveIcon={!mergedDisabled && showRemoveIcon}
|
showRemoveIcon={realShowRemoveIcon}
|
||||||
showPreviewIcon={showPreviewIcon}
|
showPreviewIcon={showPreviewIcon}
|
||||||
showDownloadIcon={showDownloadIcon}
|
showDownloadIcon={showDownloadIcon}
|
||||||
removeIcon={removeIcon}
|
removeIcon={removeIcon}
|
||||||
|
@ -579,6 +579,34 @@ describe('Upload List', () => {
|
|||||||
unmount();
|
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 () => {
|
it('should support custom onClick in custom icon', async () => {
|
||||||
const handleRemove = jest.fn();
|
const handleRemove = jest.fn();
|
||||||
const handleChange = jest.fn();
|
const handleChange = jest.fn();
|
||||||
|
Loading…
Reference in New Issue
Block a user