-
-
Notifications
You must be signed in to change notification settings - Fork 7k
fix(VFileUpload): filter files based on accepted type if passed (#21150) #21158
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
Conversation
Do we currently handle this use-case in VFileInput? |
Will check I wasn't able to see if we handle this already there. |
We currently don't handle this on |
8609aa5
to
63b48ca
Compare
Would it then be considered a bug for that component as well? If so, let's implement a shared fix. |
Yes |
I will work on adding the fix on |
This check could probably be moved to the useProxiedModel transformOut callback. |
Thanks will check and try to move this solution to that part. |
d775471
to
3d63982
Compare
3642a4d
to
bcc117f
Compare
bcc117f
to
99576a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue in VFileUpload where files were not being filtered by the accepted type and updates the file input and drag-and-drop event handling accordingly.
- Introduces a new helper function filterFilesByAcceptType to restrict files by type.
- Updates the model conversion functions in VFileUpload and VFileInput components to apply file filtering.
- Adjusts event handlers for drag-and-drop and file input change to use the new filtering logic.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
packages/vuetify/src/util/helpers.ts | Adds the filterFilesByAcceptType helper for file type filtering. |
packages/vuetify/src/labs/VFileUpload/VFileUpload.tsx | Integrates file filtering in model conversion and modifies the drag-and-drop event handler. |
packages/vuetify/src/components/VFileInput/tests/VFileInput.spec.browser.tsx | Updates the test to include an accept attribute. |
packages/vuetify/src/components/VFileInput/VFileInput.tsx | Incorporates file filtering in model conversion and event handlers. |
export function filterFilesByAcceptType (files: null | FileList | File[], acceptType?: string): File[] { | ||
if (!files) return [] | ||
if (!acceptType) return Array.from(files) | ||
return Array.from(files).filter(file => file.type === acceptType) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File type will be dependent provided from the user, like in the example linked on this PR, but do let me know if it is worthwhile to add the suggestion of copilot thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
support for image/png, image/jpeg
or wildcards image/*
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this one it will depend on the type the that user set if no type was set it will return what was uploaded by default with no restriction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what happens when user sets accept="image/*"
and selects jpeg image with type
of image/jpeg
that does not strictly match the accept
attribute value... the file does not pass out of this function. None of the files get out when the user is using wildcards or even comma-separated list of types.
433ba1c
to
5ff49bf
Compare
I don't know how I feel about having all of this functionality in the transform out function: https://github.com/vuetifyjs/vuetify/pull/21158/files#diff-1782c90664c1a45585f4b491f5801e24eeeaca9cd2c0b96ebfa168d37baa4c92R103-R118 @KaelWD is this what you meant? |
8e0e4d4
to
ed21f30
Compare
chore(VFileInput): move filter to shared function chore(VFileUpload): update to use shared function
fix(VFileInput): same with VFileUpload filter if accept type passed refactor(helper): return empty if no files passed refactor(helper): return files as array if no accept type passed
feat(VFileUpload): accept File[] as type input on filter
- to be able to identify the event type when a model change on transform out
- fixes unit test issue on VFileInput not emit change on blur
ed21f30
to
9333d52
Compare
Bringing @J-Sek into this since he's ventured into file land. |
Pull request was converted to draft
4ed69b3
to
e0f8f68
Compare
Replaced by: #21576 |
Description
Component
VFileUpload
allows unsupported files to be included in the list if accept type is passed.