Skip to content
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

Input with type="file" and two-way binding doesn't track empty fileList #8316

Closed
TGlide opened this issue Feb 23, 2023 · 2 comments
Closed

Comments

@TGlide
Copy link
Member

TGlide commented Feb 23, 2023

Describe the bug

If you have an input like so:

<input type="file" bind:files bind:this={input}>

And set files to null or (new DataTransfer()).files, after having chosen a file, input.files still contains the file chosen. The only way to properly reset both files and input.files is setting them both to (new DataTransfer()).files.

Reproduction

https://svelte.dev/repl/c0813e09c2f744e499e86975c9eea13f?version=3.55.1

Logs

No response

System Info

Browsers: Firefox 110.0; Chrome 110.0.5481.177
OS: Window 10
Svelte Version: 3.55.1

Severity

annoyance

@brunnerh
Copy link
Member

brunnerh commented Feb 24, 2023

Note that you cannot reset the selected files with null according to the spec:

On setting, it must run these steps:

But it looks like the binding is only one-way (read). Related:

Where Rich Harris stated:

Svelte shouldn't attempt to assign to input.files

It should, though. The spec does not define the attribute as readonly.

@dummdidumm
Copy link
Member

Svelte 5 will allow writing to bind:files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants