-
Notifications
You must be signed in to change notification settings - Fork 936
feat(FileUpload): add directUpdate option to skip upload preview #5366
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
base: v4
Are you sure you want to change the base?
feat(FileUpload): add directUpdate option to skip upload preview #5366
Conversation
commit: |
b42614d to
a183f6c
Compare
| } | ||
| function onUpdate(files: File[], reset = false) { | ||
| // @ts-expect-error - 'target' does not exist in type 'EventInit' |
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.
When directUpdate is enabled, the component emits the change event with raw files but never updates modelValue, causing files to not display in the UI and creating a disconnect between the event payload and component state.
View Details
π Patch Details
diff --git a/src/runtime/components/FileUpload.vue b/src/runtime/components/FileUpload.vue
index e481598a..e56ff625 100644
--- a/src/runtime/components/FileUpload.vue
+++ b/src/runtime/components/FileUpload.vue
@@ -219,14 +219,7 @@ function formatFileSize(bytes: number): string {
}
function onUpdate(files: File[], reset = false) {
- // @ts-expect-error - 'target' does not exist in type 'EventInit'
- let event = new Event('change', { target: { value: files } })
-
- if (props.directUpdate) {
- emits('change', event)
- return
- }
-
+ // Update modelValue first to ensure files display in UI
if (props.multiple) {
if (reset) {
modelValue.value = files as (M extends true ? File[] : File) | null
@@ -238,6 +231,14 @@ function onUpdate(files: File[], reset = false) {
modelValue.value = files?.[0] as (M extends true ? File[] : File) | null
}
+ // @ts-expect-error - 'target' does not exist in type 'EventInit'
+ let event = new Event('change', { target: { value: files } })
+
+ if (props.directUpdate) {
+ emits('change', event)
+ return
+ }
+
// @ts-expect-error - 'target' does not exist in type 'EventInit'
event = new Event('change', { target: { value: modelValue.value } })
emits('change', event)
Analysis
FileUpload onUpdate() bypasses modelValue update when directUpdate=true
What fails: FileUpload component's onUpdate() function (lines 221-228) returns early when directUpdate is true without updating modelValue, causing uploaded files not to display in the UI
How to reproduce:
// Mount FileUpload with directUpdate=true
const wrapper = mount(FileUpload, { props: { directUpdate: true } })
const input = wrapper.find('input')
await setFilesOnInput(input, [new File(['test'], 'test.jpg')])
// modelValue remains null, template shows no filesResult: Template condition v-if="modelValue && (Array.isArray(modelValue) ? modelValue.length : true)" evaluates to false, files don't render in UI despite successful upload and event emission
Expected: Files should display in dropzone UI regardless of directUpdate mode - modelValue should be updated before the early return in directUpdate path
Fix: Move modelValue update logic before directUpdate check so template can render files in both modes while preserving different event payload behaviors
|
@dennisadriaans What do you think of #5443 instead? A simple |
π Linked issue
Resolves #5367
β Type of change
π Description
In some cases, we would like to skip the preview step and simply emit the change event. For example, in a Google Drive-like environment, the file should be uploaded immediately upon drop, removing the need for an explicit submission of the queue or a preview.
π Checklist