Skip to content

Commit 0363eba

Browse files
committed
feat: Support non-click folder upload
1 parent 4958954 commit 0363eba

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

docs/demo/dragOnlyDirectory.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: dragOnlyDirectory
3+
nav:
4+
title: Demo
5+
path: /demo
6+
---
7+
8+
<code src="../examples/dragOnlyDirectory.tsx"></code>
9+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* eslint no-console:0 */
2+
import React from 'react';
3+
import Upload from 'rc-upload';
4+
5+
const props = {
6+
action: '/upload.do',
7+
type: 'drag',
8+
directory: 'nonClick' as 'nonClick',
9+
beforeUpload(file, fileList) {
10+
console.log('beforeUpload', file.name, fileList);
11+
},
12+
onStart: file => {
13+
console.log('onStart', file.name);
14+
},
15+
onSuccess(file) {
16+
console.log('onSuccess', file);
17+
},
18+
onProgress(step, file) {
19+
console.log('onProgress', Math.round(step.percent), file.name);
20+
},
21+
onError(err) {
22+
console.log('onError', err);
23+
},
24+
style: { display: 'inline-block', width: 200, height: 200, background: '#eee' },
25+
// openFileDialogOnClick: false
26+
};
27+
28+
const Test = () => {
29+
return (
30+
<div
31+
style={{
32+
margin: 100,
33+
}}
34+
>
35+
<div>
36+
<Upload {...props}>
37+
<a>开始上传,只支持拖拽上传文件夹</a>
38+
</Upload>
39+
</div>
40+
</div>
41+
);
42+
};
43+
44+
export default Test;

src/AjaxUploader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class AjaxUploader extends Component<UploadProps> {
335335
});
336336
// because input don't have directory/webkitdirectory type declaration
337337
const dirProps: any =
338-
directory || folder ? { directory: 'directory', webkitdirectory: 'webkitdirectory' } : {};
338+
directory === true || folder ? { directory: 'directory', webkitdirectory: 'webkitdirectory' } : {};
339339
const events = disabled
340340
? {}
341341
: {

src/interface.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface UploadProps
1414
action?: Action;
1515
method?: UploadRequestMethod;
1616
/** @deprecated Please use `folder` instead */
17-
directory?: boolean;
17+
directory?: boolean | 'nonClick';
1818
folder?: boolean;
1919
data?: Record<string, unknown> | ((file: RcFile | string | Blob) => Record<string, unknown>);
2020
headers?: UploadRequestHeader;

0 commit comments

Comments
 (0)