pqina / filepond

🌊 A flexible and fun JavaScript file upload library
https://pqina.nl/filepond
MIT License
15.25k stars 828 forks source link

Pasting image to focused FilePond, but affects all FilePond instances #794

Open trydofor opened 2 years ago

trydofor commented 2 years ago

Is there an existing issue for this?

Have you updated Vue FilePond, FilePond, and all plugins?

Describe the bug

https://codesandbox.io/s/epic-wilbur-brhks?file=/src/components/HelloWorld.vue

As HelloWorld.vue showed, there are 2 instances of FilePond1 and FilePond2. and I paste a clipboard image to FilePond1, and want only FilePond1 get the image. but both FilePond1 and FilePond2 get the image.

Reproduction

in https://codesandbox.io/s/epic-wilbur-brhks?file=/src/components/HelloWorld.vue

Environment

- Device:Macbook 
- OS: catalina
- Broser: chrome
- Vue version: 3
- vue-filepond: 7
rikschennink commented 2 years ago

Currently this is not supported. FilePond will test if the current element is a textarea or input, and if so, will not handle the paste action. Else all FilePond instances will pick it up as it's a document level event.

To know where to add the pasted file we'd need to focus the filepond field but focussing it also opens the file browser.

Alternatively we could use the paste location, not sure that is available on mobile devices and/or files can be pasted there.

trydofor commented 2 years ago

thanks @rikschennink
another suggest, i read FilePond api could it's ok if let user handle focus event and browse() method

rikschennink commented 2 years ago

@trydofor I'm not sure if I understand what you mean, please elaborate

anonghuser commented 1 year ago

@trydofor you could try to update the allowPaste option on the different instances based on their or nearby/related inputs/fieldsets/forms visibility/focus status.

@rikschennink instead of constantly keeping track of visibility/focus changes and keeping allowPaste accurate at all times it could be easier in some cases to just make a decision at the time of pasting. So a cancellable onpaste event might be a good addition.

P.S.: The thing you mentioned where paste is ignored with text input or textarea in focus might be bad for some use cases too, I hope this can be overridden.

captenmasin commented 1 year ago

@trydofor you could try to update the allowPaste option on the different instances based on their or nearby/related inputs/fieldsets/forms visibility/focus status.

@rikschennink instead of constantly keeping track of visibility/focus changes and keeping allowPaste accurate at all times it could be easier in some cases to just make a decision at the time of pasting. So a cancellable onpaste event might be a good addition.

P.S.: The thing you mentioned where paste is ignored with text input or textarea in focus might be bad for some use cases too, I hope this can be overridden.

I'm having this issue right now in fact. I have a comment section component which includes a comment form and a reply form for each comment, and I'd really like to be able to paste whilst focussed in the textarea and instantly upload an image (similar to this Github text form or the twitter form)

rikschennink commented 1 year ago

@captenmasin If you listen for the 'paste' event on the textarea does it fire? If so you can get any files and add them to the FilePond instance with the addFile method.