File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,9 @@ import 'core-js/fn/string/ends-with';
14
14
15
15
export default function ( file , acceptedFiles ) {
16
16
if ( file && acceptedFiles ) {
17
- const acceptedFilesArray = acceptedFiles . split ( ',' ) ;
17
+ const acceptedFilesArray = ( Array . isArray ( acceptedFiles ) ?
18
+ acceptedFiles :
19
+ acceptedFiles . split ( ',' ) ) ;
18
20
const fileName = file . name || '' ;
19
21
const mimeType = file . type || '' ;
20
22
const baseMimeType = mimeType . replace ( / \/ .* $ / , '' ) ;
Original file line number Diff line number Diff line change @@ -135,4 +135,20 @@ describe('accept', () => {
135
135
type : 'random/type'
136
136
} , acceptedMimeTypes ) ) . toBe ( true ) ;
137
137
} ) ;
138
+
139
+ it ( 'should allow accepted files passed to be an array' , ( ) => {
140
+ const acceptedMimeTypes = [ 'img/jpeg' , '.pdf' ] ;
141
+ expect ( accept ( {
142
+ name : 'testfile.pdf' ,
143
+ type : 'random/type'
144
+ } , acceptedMimeTypes ) ) . toBe ( true ) ;
145
+ expect ( accept ( {
146
+ name : 'testfile.jpg' ,
147
+ type : 'img/jpeg'
148
+ } , acceptedMimeTypes ) ) . toBe ( true ) ;
149
+ expect ( accept ( {
150
+ name : 'testfile' ,
151
+ type : 'application/json'
152
+ } , acceptedMimeTypes ) ) . toBe ( false ) ;
153
+ } ) ;
138
154
} ) ;
You can’t perform that action at this time.
0 commit comments