From 8fc3cb8d2419202bce2574c9ee3182086d021dc1 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 11 Feb 2019 20:29:43 +0800 Subject: [PATCH] :bug: 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 --- components/upload/Upload.tsx | 12 +++++++++--- components/upload/__tests__/upload.test.js | 13 +++++++++++++ components/upload/interface.tsx | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/components/upload/Upload.tsx b/components/upload/Upload.tsx index 3a8cee6205..9b6c921241 100644 --- a/components/upload/Upload.tsx +++ b/components/upload/Upload.tsx @@ -316,11 +316,17 @@ class Upload extends React.Component { [`${prefixCls}-disabled`]: disabled, }); - const uploadButton = children ? ( -
+ // 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 = ( +
- ) : null; + ); if (listType === 'picture-card') { return ( diff --git a/components/upload/__tests__/upload.test.js b/components/upload/__tests__/upload.test.js index 9e66e54b12..a7466cbad9 100644 --- a/components/upload/__tests__/upload.test.js +++ b/components/upload/__tests__/upload.test.js @@ -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( + + + , + ); + + 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 = [ { diff --git a/components/upload/interface.tsx b/components/upload/interface.tsx index bd51ee8ae2..bc372c713b 100755 --- a/components/upload/interface.tsx +++ b/components/upload/interface.tsx @@ -76,6 +76,7 @@ export interface UploadProps { withCredentials?: boolean; openFileDialogOnClick?: boolean; locale?: UploadLocale; + id?: string; } export interface UploadState {