Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: openFileDialogOnClick supports a function that returns a boolean… #571

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ React.render(<Upload />, container);
|beforeUpload| function |null| before upload check, return false or a rejected Promise will stop upload, only for modern browsers|
|customRequest | function | null | provide an override for the default xhr behavior for additional customization|
|withCredentials | boolean | false | ajax upload with cookie send |
|openFileDialogOnClick | boolean | true | useful for drag only upload as it does not trigger on enter key or click event |
|openFileDialogOnClick | boolean/function():boolean | true | useful for drag only upload as it does not trigger on enter key or click event |

#### onError arguments

Expand Down
9 changes: 7 additions & 2 deletions src/AjaxUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ class AjaxUploader extends Component<UploadProps> {
this.fileInput = node;
};

eventHandler = (fn: (() => boolean) | boolean, originFn: Function, e: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => {
if (typeof fn === 'function' ? fn() : fn) {
originFn(e);
}
};
render() {
const {
component: Tag,
Expand Down Expand Up @@ -295,8 +300,8 @@ class AjaxUploader extends Component<UploadProps> {
const events = disabled
? {}
: {
onClick: openFileDialogOnClick ? this.onClick : () => {},
onKeyDown: openFileDialogOnClick ? this.onKeyDown : () => {},
onClick: (e) => this.eventHandler(openFileDialogOnClick, this.onClick, e),
onKeyDown: (e) => this.eventHandler(openFileDialogOnClick, this.onKeyDown, e),
onMouseEnter,
onMouseLeave,
onDrop: this.onFileDrop,
Expand Down
2 changes: 1 addition & 1 deletion src/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface UploadProps
) => BeforeUploadFileType | Promise<void | BeforeUploadFileType> | void;
customRequest?: (option: UploadRequestOption) => void | { abort: () => void };
withCredentials?: boolean;
openFileDialogOnClick?: boolean;
openFileDialogOnClick?: boolean | (() => boolean);
prefixCls?: string;
id?: string;
onMouseEnter?: (e: React.MouseEvent<HTMLDivElement>) => void;
Expand Down