Skip to content

Commit ba2ef61

Browse files
authored
chore: accept should skip when select files rather than dir (#329)
1 parent 00abfee commit ba2ef61

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/AjaxUploader.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ class AjaxUploader extends Component<UploadProps> {
3232
private _isMounted: boolean;
3333

3434
onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
35+
const { accept, directory } = this.props;
3536
const { files } = e.target;
36-
const acceptedFiles = [...files].filter((file: RcFile) => attrAccept(file, this.props.accept));
37+
const acceptedFiles = [...files].filter(
38+
(file: RcFile) => !directory || attrAccept(file, accept),
39+
);
3740
this.uploadFiles(acceptedFiles);
3841
this.reset();
3942
};

tests/uploader.spec.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,12 @@ describe('uploader', () => {
460460
},
461461
};
462462

463-
function test(desc, value, files, expectCallTimes, errorMessage) {
463+
function test(desc, value, files, expectCallTimes, errorMessage, extraProps) {
464464
it(desc, done => {
465465
resetWarned();
466466
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
467467

468-
uploader = mount(<Uploader {...props} accept={value} />);
468+
uploader = mount(<Uploader {...props} {...extraProps} accept={value} />);
469469
const input = uploader.find('input').first();
470470
input.simulate('change', { target: { files } });
471471
const mockStart = jest.fn();
@@ -633,6 +633,26 @@ describe('uploader', () => {
633633
2,
634634
"Warning: Upload takes an invalidate 'accept' type 'jpg'.Skip for check.",
635635
);
636+
637+
test(
638+
'should skip when select file',
639+
'.png',
640+
[
641+
{
642+
name: 'accepted.png',
643+
type: 'image/png',
644+
},
645+
{
646+
name: 'unaccepted.text',
647+
type: 'text/plain',
648+
},
649+
],
650+
2,
651+
'',
652+
{
653+
directory: false,
654+
},
655+
);
636656
});
637657

638658
describe('transform file before request', () => {

0 commit comments

Comments
 (0)