Skip to content

修复拖拽不符合要求的文件,仍然调用beforeUpload #627

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

Open
wants to merge 3 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 src/AjaxUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AjaxUploader extends Component<UploadProps> {
let acceptFiles = [...files].filter((file: RcFile) => attrAccept(file, accept));

if (multiple === false) {
acceptFiles = files.slice(0, 1);
acceptFiles = acceptFiles.slice(0, 1);
}

this.uploadFiles(acceptFiles);
Expand Down
25 changes: 25 additions & 0 deletions tests/uploader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,32 @@ describe('uploader', () => {
done();
}, 100);
});

it('drag unaccepted type files with multiple false to upload will not trigger onStart ', done => {
const { container } = render(<Upload {...props} multiple={false} />);

const input = container.querySelector('input')!;
const files = [
{
name: 'success.jpg',
toString() {
return this.name;
},
},
];
(files as any).item = (i: number) => files[i];

const mockStart = jest.fn();
handlers.onStart = mockStart;
fireEvent.drop(input, {
dataTransfer: { files },
});
setTimeout(() => {
expect(mockStart.mock.calls.length).toBe(0);
done();
}, 100);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是应该检测 beforeUpload 的触发情况?


it('drag files with multiple false', done => {
const { container } = render(<Upload {...props} multiple={false} />);
const input = container.querySelector('input')!;
Expand Down