🐛 Fix always uploading if upload button is hidden during

close #14779

caused by the previous fix in #14298

reverted and change another way to fix #14299
This commit is contained in:
afc163 2019-02-11 20:29:43 +08:00 committed by 偏右
parent dbc2e9d180
commit 8fc3cb8d24
3 changed files with 23 additions and 3 deletions

View File

@ -316,11 +316,17 @@ class Upload extends React.Component<UploadProps, UploadState> {
[`${prefixCls}-disabled`]: disabled,
});
const uploadButton = children ? (
<div className={uploadButtonCls}>
// Remove id to avoid open by label when trigger is hidden
// https://github.com/ant-design/ant-design/issues/14298
if (!children) {
delete rcUploadProps.id;
}
const uploadButton = (
<div className={uploadButtonCls} style={children ? undefined : { display: 'none' }}>
<RcUpload {...rcUploadProps} ref={this.saveUpload} />
</div>
) : null;
);
if (listType === 'picture-card') {
return (

View File

@ -188,6 +188,19 @@ describe('Upload', () => {
});
});
// https://github.com/ant-design/ant-design/issues/14779
it('should contain input file control if upload button is hidden', () => {
const wrapper = mount(
<Upload action="http://upload.com">
<button type="button">upload</button>
</Upload>,
);
expect(wrapper.find('input[type="file"]').length).toBe(1);
wrapper.setProps({ children: null });
expect(wrapper.find('input[type="file"]').length).toBe(1);
});
it('should be controlled by fileList', () => {
const fileList = [
{

View File

@ -76,6 +76,7 @@ export interface UploadProps {
withCredentials?: boolean;
openFileDialogOnClick?: boolean;
locale?: UploadLocale;
id?: string;
}
export interface UploadState {