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: use type to deciding whether to allow drag #549

Open
wants to merge 1 commit 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
7 changes: 5 additions & 2 deletions src/AjaxUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class AjaxUploader extends Component<UploadProps> {
onMouseEnter,
onMouseLeave,
hasControlInside,
type,
...otherProps
} = this.props;
const cls = clsx({
Expand All @@ -298,8 +299,10 @@ class AjaxUploader extends Component<UploadProps> {
onKeyDown: openFileDialogOnClick ? this.onKeyDown : () => {},
onMouseEnter,
onMouseLeave,
onDrop: this.onFileDrop,
onDragOver: this.onFileDrop,
...(type === 'drag' ? {
onDrop: this.onFileDrop,
onDragOver: this.onFileDrop,
} : {}),
tabIndex: hasControlInside ? undefined : '0',
};
return (
Expand Down
11 changes: 7 additions & 4 deletions tests/uploader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ describe('uploader', () => {
});

it('drag to upload', done => {
const input = uploader.container.querySelector('input')!;
const { container } = render(<Upload {...props} type='drag' />);
const input = container.querySelector('input')!;

const files = [
{
Expand Down Expand Up @@ -243,7 +244,8 @@ describe('uploader', () => {
});

it('drag unaccepted type files to upload will not trigger onStart', done => {
const input = uploader.container.querySelector('input')!;
const { container } = render(<Upload {...props} type='drag'/>);
const input = container.querySelector('input')!;
const files = [
{
name: 'success.jpg',
Expand All @@ -266,7 +268,7 @@ describe('uploader', () => {
});

it('drag files with multiple false', done => {
const { container } = render(<Upload {...props} multiple={false} />);
const { container } = render(<Upload {...props} multiple={false} type='drag'/>);
const input = container.querySelector('input')!;
const files = [
new File([''], 'success.png', { type: 'image/png' }),
Expand Down Expand Up @@ -400,7 +402,8 @@ describe('uploader', () => {
});

it('dragging and dropping a non file with a file does not prevent the file from being uploaded', done => {
const input = uploader.container.querySelector('input')!;
const { container } = render(<Upload {...props} type='drag' />);
const input = container.querySelector('input')!;
const file = {
name: 'success.png',
};
Expand Down
Loading