Skip to content

Commit b45b533

Browse files
committed
feat: rename allowPasteUpload to pastable
1 parent f62c96e commit b45b533

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ React.render(<Upload />, container);
8484
|customRequest | function | null | provide an override for the default xhr behavior for additional customization|
8585
|withCredentials | boolean | false | ajax upload with cookie send |
8686
|openFileDialogOnClick | boolean | true | useful for drag only upload as it does not trigger on enter key or click event |
87-
|allowPasteUpload | boolean | false | support paste upload |
87+
|pastable | boolean | false | support paste upload |
8888

8989
#### onError arguments
9090

docs/examples/paste.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const props = {
66
action: '/upload.do',
77
type: 'drag',
88
accept: '.png',
9-
allowPasteUpload: true,
9+
pastable: true,
1010
beforeUpload(file) {
1111
console.log('beforeUpload', file.name);
1212
},

docs/examples/pasteDirectory.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const props = {
77
type: 'drag',
88
accept: '.png',
99
directory: true,
10-
allowPasteUpload: true,
10+
pastable: true,
1111
beforeUpload(file) {
1212
console.log('beforeUpload', file.name);
1313
},

src/AjaxUploader.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,38 @@ class AjaxUploader extends Component<UploadProps> {
103103
}
104104
};
105105

106-
onPrePaste(e: ClipboardEvent) {
107-
const { allowPasteUpload } = this.props;
106+
onPrePaste = (e: ClipboardEvent) => {
107+
const { pastable } = this.props;
108108

109-
if (allowPasteUpload) {
109+
if (pastable) {
110110
this.onFileDropOrPaste(e);
111111
}
112-
}
112+
};
113113

114114
componentDidMount() {
115115
this._isMounted = true;
116116

117-
const { allowPasteUpload } = this.props;
117+
const { pastable } = this.props;
118118

119-
if (allowPasteUpload) {
120-
document.addEventListener('paste', this.onPrePaste.bind(this));
119+
if (pastable) {
120+
document.addEventListener('paste', this.onPrePaste);
121121
}
122122
}
123123

124124
componentWillUnmount() {
125125
this._isMounted = false;
126126
this.abort();
127-
document.removeEventListener('paste', this.onPrePaste.bind(this));
127+
document.removeEventListener('paste', this.onPrePaste);
128+
}
129+
130+
componentDidUpdate(prevProps: UploadProps) {
131+
const { pastable } = this.props;
132+
133+
if (pastable && !prevProps.pastable) {
134+
document.addEventListener('paste', this.onPrePaste);
135+
} else if (!pastable && prevProps.pastable) {
136+
document.removeEventListener('paste', this.onPrePaste);
137+
}
128138
}
129139

130140
uploadFiles = (files: File[]) => {

src/interface.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface UploadProps
4444
input?: React.CSSProperties;
4545
};
4646
hasControlInside?: boolean;
47-
allowPasteUpload?: boolean;
47+
pastable?: boolean;
4848
}
4949

5050
export interface UploadProgressEvent extends Partial<ProgressEvent> {

tests/uploader.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ describe('uploader', () => {
350350
});
351351

352352
it('paste to upload', done => {
353-
const { container } = render(<Upload {...props} allowPasteUpload />);
353+
const { container } = render(<Upload {...props} pastable />);
354354
const input = container.querySelector('input')!;
355355

356356
const files = [
@@ -406,7 +406,7 @@ describe('uploader', () => {
406406
});
407407

408408
it('paste files with multiple false', done => {
409-
const { container } = render(<Upload {...props} multiple={false} allowPasteUpload />);
409+
const { container } = render(<Upload {...props} multiple={false} pastable />);
410410
const input = container.querySelector('input')!;
411411
const files = [
412412
new File([''], 'success.png', { type: 'image/png' }),
@@ -780,7 +780,7 @@ describe('uploader', () => {
780780
});
781781

782782
it('paste directory', done => {
783-
const { container } = render(<Upload {...props} allowPasteUpload />);
783+
const { container } = render(<Upload {...props} pastable />);
784784
const rcUpload = container.querySelector('.rc-upload')!;
785785
const files = {
786786
name: 'foo',

0 commit comments

Comments
 (0)