thecodejack / svelte-file-dropzone

Svelte component for fileupload
https://svelte-file-dropzone.netlify.app/
252 stars 45 forks source link

forward `$$restProps` or expose `id` prop or `rootRef` #162

Closed huntabyte closed 1 month ago

huntabyte commented 5 months ago

I have a button in my app that, when clicked, I want the same behavior as when a user clicks the dropzone.

Currently, we can't pass any additional data-* attributes or id to the underlying <div> to get a reference to it.

roberrrt-s commented 1 month ago

Can I one-up this one.

arackaf commented 1 month ago

Yeah def - lemme take a look tonight or tomorrow

roberrrt-s commented 1 month ago

My hacky workaround currently is:

    function openFileInput() {
        // I hate everything about this but it works.
        const input = document.querySelector('.drop-element input[type="file"]') as HTMLInputElement;

        if(input) {
            input.click();
        }
    }

Where .drop-element is the dropzoner per

<Dropzone containerClasses={`drop-element${dragged || files.accepted.length > 0 || files.rejected.length > 0 ? '' : ' hidden'}`} on:drop={dropHandler} disableDefaultStyles={true} on:dragenter={dragEnterHandler} on:dragleave={dragLeaveHandler}>

But yeah, it works quite well!

arackaf commented 1 month ago

Gah - sorry! I promise I'll get to this tomorrow.

arackaf commented 1 month ago

This should be released in 2.0.8

roberrrt-s commented 1 month ago

That's awesome. Thank's a lot!