From dc73c0e57e3fa5e682b3ceb936b159c1d7bbd116 Mon Sep 17 00:00:00 2001 From: linxianxi <904492381@qq.com> Date: Fri, 2 Jun 2023 15:47:36 +0800 Subject: [PATCH] feat: add showOpenFilePicker method --- README.md | 2 ++ src/AjaxUploader.tsx | 4 ++++ src/Upload.tsx | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 74906767..67be8ac4 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,8 @@ customRequest callback is passed an object with: abort(file?: File) => void: abort the uploading file +showOpenFilePicker() => void: open file picker + ## License rc-upload is released under the MIT license. diff --git a/src/AjaxUploader.tsx b/src/AjaxUploader.tsx index caa7b7d1..ae028335 100644 --- a/src/AjaxUploader.tsx +++ b/src/AjaxUploader.tsx @@ -41,6 +41,10 @@ class AjaxUploader extends Component { this.reset(); }; + showOpenFilePicker = () => { + this.fileInput?.click(); + }; + onClick = (e: React.MouseEvent | React.KeyboardEvent) => { const el = this.fileInput; if (!el) { diff --git a/src/Upload.tsx b/src/Upload.tsx index 548aca17..9ac9b05a 100644 --- a/src/Upload.tsx +++ b/src/Upload.tsx @@ -29,6 +29,10 @@ class Upload extends Component { this.uploader.abort(file); } + showOpenFilePicker() { + this.uploader.showOpenFilePicker(); + } + saveUploader = (node: AjaxUpload) => { this.uploader = node; };