mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 06:03:38 +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,
|
||||
} = 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}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user