-
Notifications
You must be signed in to change notification settings - Fork 241
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
fix: dropzone id and event handling #433
Conversation
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
3acc708
to
8934812
Compare
Thank you for your PR. Users may use more than one dropzone. This means we can't use the same id:
This can be avoided by:
So if users don't assign the |
What about: import generateId from '$lib/utils/generateId';
export let id: string = generateId(); |
But is that not the same as my code? Users can set the id value 'dropzone-file' is just the default value.
I think default values should be able to provide value for the lazy user. If they are generated they would be different between each build and could lead to confusion. What do you think? |
What will happen then if you have to drop zones on the page. With the generated id no issue, with the default value you'll end up with double id. |
Sure but you can set the id. But even if you have just one dropzone on your page which is part of a form you are forced to set an id because otherwise, the file will appear always under a different payload property (if send in a form etc). If you still prefer the generated approach let me know. |
There are lots of valuable input in that proposal. Few comments:
<script lang="ts">
import classNames from 'classnames';
export let value: string = '';
export let files: FileList | undefined = undefined;
export let defaultClass: string =
'flex flex-col justify-center items-center w-full h-64 bg-gray-50 rounded-lg border-2 border-gray-300 border-dashed cursor-pointer dark:hover:bg-bray-800 dark:bg-gray-700 hover:bg-gray-100 dark:border-gray-600 dark:hover:border-gray-500 dark:hover:bg-gray-600';
let input: HTMLInputElement;
function keydown(ev: KeyboardEvent) {
if ([' ', 'Enter'].includes(ev.key)) {
ev.preventDefault();
input.click();
}
}
</script>
<label
class={classNames(defaultClass, $$props.class)}
tabIndex="0"
on:keydown={keydown}
on:focus
on:blur
on:mouseenter
on:mouseleave
on:mouseover
on:dragenter
on:dragleave
on:dragover
on:drop>
<slot />
<input {...$$restProps} bind:value bind:files bind:this={input} type="file" class="hidden" on:change on:click />
</label> |
fc34886
to
2182291
Compare
@jjagielka awesome, you are absolutely right I adopted your suggestion. π |
@shinokada please approve that PR. |
Closes #432
π Description
Dropzone is broken as hidden input has not have an id.
I added an id to the hidden input and in the second commit I added a id prop as the example page shows that Dropzone gets passed an id.
β Checks