mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 11:08:45 +08:00
fix: Upload listType="picture-card" select button when children is empty (#36196)
* fix: Upload listType="picture-card" select button should be hidden when children is empty close #36183 * test: fix test case
This commit is contained in:
parent
2971e3b081
commit
7357f55d52
@ -406,17 +406,19 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
|
||||
</div>
|
||||
);
|
||||
|
||||
const uploadButton = renderUploadButton(children ? undefined : { display: 'none' });
|
||||
|
||||
if (listType === 'picture-card') {
|
||||
return (
|
||||
<span className={classNames(`${prefixCls}-picture-card-wrapper`, className)}>
|
||||
{renderUploadList(renderUploadButton(), !!children)}
|
||||
{renderUploadList(uploadButton, !!children)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<span className={className}>
|
||||
{renderUploadButton(children ? undefined : { display: 'none' })}
|
||||
{uploadButton}
|
||||
{renderUploadList()}
|
||||
</span>
|
||||
);
|
||||
|
@ -937,8 +937,11 @@ describe('Upload', () => {
|
||||
);
|
||||
|
||||
rerender(<Upload listType="picture-card" />);
|
||||
expect(container.querySelector('.ant-upload-select-picture-card')).not.toHaveStyle({
|
||||
display: 'none',
|
||||
expect(container.querySelector('.ant-upload-select-picture-card')).toHaveClass(
|
||||
'ant-upload-animate-inline-leave-start',
|
||||
);
|
||||
expect(container.querySelector('.ant-upload-select-picture-card')).toHaveStyle({
|
||||
pointerEvents: 'none',
|
||||
});
|
||||
|
||||
// Motion leave status change: start > active
|
||||
@ -947,10 +950,9 @@ describe('Upload', () => {
|
||||
});
|
||||
|
||||
fireEvent.animationEnd(container.querySelector('.ant-upload-select-picture-card'));
|
||||
|
||||
expect(container.querySelector('.ant-upload-select-picture-card')).toHaveStyle({
|
||||
display: 'none',
|
||||
});
|
||||
expect(container.querySelector('.ant-upload-select-picture-card')).not.toHaveClass(
|
||||
'ant-upload-animate-inline-leave-start',
|
||||
);
|
||||
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
@ -1499,4 +1499,43 @@ describe('Upload List', () => {
|
||||
});
|
||||
unmount();
|
||||
});
|
||||
|
||||
describe('should not display upload file-select button when listType is picture-card and children is empty', () => {
|
||||
it('when showUploadList is true', () => {
|
||||
const list = [
|
||||
{
|
||||
uid: '0',
|
||||
name: 'xxx.png',
|
||||
status: 'done',
|
||||
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
||||
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
||||
},
|
||||
];
|
||||
const { container: wrapper, unmount } = render(
|
||||
<Upload fileList={list} listType="picture-card" />,
|
||||
);
|
||||
expect(wrapper.querySelectorAll('.ant-upload-select').length).toBe(1);
|
||||
expect(wrapper.querySelectorAll('.ant-upload-select')[0].style.display).toBe('none');
|
||||
unmount();
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/issues/36183
|
||||
it('when showUploadList is false', () => {
|
||||
const list = [
|
||||
{
|
||||
uid: '0',
|
||||
name: 'xxx.png',
|
||||
status: 'done',
|
||||
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
||||
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png',
|
||||
},
|
||||
];
|
||||
const { container: wrapper, unmount } = render(
|
||||
<Upload fileList={list} showUploadList={false} listType="picture-card" />,
|
||||
);
|
||||
expect(wrapper.querySelectorAll('.ant-upload-select').length).toBe(1);
|
||||
expect(wrapper.querySelectorAll('.ant-upload-select')[0].style.display).toBe('none');
|
||||
unmount();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user