Skip to content

Commit

Permalink
fix(VFileInput): remove typeof filter in arrayValue, improve prop val…
Browse files Browse the repository at this point in the history
…idator

ie11 cannot generate File objects

fixes #10306
  • Loading branch information
johnleider committed Jan 27, 2020
1 parent f289b05 commit 140d82c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/vuetify/src/components/VFileInput/VFileInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default VTextField.extend({
value: {
default: undefined,
validator: val => {
return typeof val === 'object' || Array.isArray(val)
return wrapInArray(val).every(v => v != null && typeof v === 'object')
},
} as PropValidator<File | File[]>,
},
Expand All @@ -86,7 +86,9 @@ export default VTextField.extend({

if (!this.showSize) return this.$vuetify.lang.t(this.counterString, fileCount)

const bytes = this.internalArrayValue.reduce((size: number, file: File) => size + file.size, 0)
const bytes = this.internalArrayValue.reduce((bytes: number, { size = 0 }: File) => {
return bytes + size
}, 0)

return this.$vuetify.lang.t(
this.counterSizeString,
Expand All @@ -95,7 +97,7 @@ export default VTextField.extend({
)
},
internalArrayValue (): File[] {
return wrapInArray(this.internalValue).filter(file => file instanceof File)
return wrapInArray(this.internalValue)
},
internalValue: {
get (): File[] {
Expand All @@ -119,9 +121,16 @@ export default VTextField.extend({
if (!this.isDirty) return [this.placeholder]

return this.internalArrayValue.map((file: File) => {
const name = this.truncateText(file.name)
const {
name = '',
size = 0,
} = file

return !this.showSize ? name : `${name} (${humanReadableFileSize(file.size, this.base === 1024)})`
const truncatedText = this.truncateText(name)

return !this.showSize
? truncatedText
: `${truncatedText} (${humanReadableFileSize(size, this.base === 1024)})`
})
},
base (): 1000 | 1024 | undefined {
Expand Down

0 comments on commit 140d82c

Please sign in to comment.