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

bind:files doesn't work on safari. But works in chrome #3226

Closed
muhajirdev opened this issue Jul 12, 2019 · 5 comments · Fixed by #3305
Closed

bind:files doesn't work on safari. But works in chrome #3226

muhajirdev opened this issue Jul 12, 2019 · 5 comments · Fixed by #3305
Labels

Comments

@muhajirdev
Copy link

muhajirdev commented Jul 12, 2019

Here's the repl.

https://svelte.dev/repl/61c6df2593cf4667ac36fb4c75c56012?version=3.6.7

<script>
	let name = 'world';
	
	let files = []
	
	$: {
		console.log(files)
	}
</script>


<input
		type="file"
		accept="image/*"
		class="w-full h-full cursor-pointer"
		bind:files />

Tried to open console. And then input a file.

On chrome it should log something. But on safari it's not working

@joernroeder
Copy link

can confirm. receiving events in chrome and firefox.

@dishuostec
Copy link

You can use change event.
https://svelte.dev/repl/f4e2ed04dfda4b2f82ee870fafcd997e?version=3.6.7

<script>
	let name = 'world';
	
	let files = []
	
	$: {
		console.log(files)
	}
	const changed = (event)=>{
		console.log('changed', event)
		files = event.target.files;
	}
</script>


<input
		type="file"
		accept="image/*"
		class="w-full h-full cursor-pointer"
		bind:files
		on:change={changed}
/>

@muhajirdev
Copy link
Author

Yup, can confirm @dishuostec's is working. Thanks man

I'll keep this issue still open tho. Perhaps bind:files is easier.

@Conduitry
Copy link
Member

I'm assuming the issue here is that file input elements don't fire the input event when they're changed? I don't have access to Safari to check. MDN reports that change and input events are supported on file inputs. I don't see anything there about differences between what these events means, and change is what's used in the code example there. It might be safe in all browsers to just implement this binding with change instead of input.

@Conduitry Conduitry added the bug label Jul 12, 2019
@pngwn
Copy link
Member

pngwn commented Jul 12, 2019

I've just checked this on safari and file inputs do indeed fire a change event when the input (file) is changed.

Conduitry added a commit to Conduitry/sveltejs_svelte that referenced this issue Jul 28, 2019
Rich-Harris added a commit that referenced this issue Jul 30, 2019
use `change` event for `bind:files`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants