Skip to content

FileInput ​

FileInput is the means to choose files, with no look of its own.

When to use ​

Use it behind a Button that the person presses: call pick() on the FileInput, taken with bind:this, to open the system's file chooser. The chosen files reach onpick. A place where files can also be dropped is a DropTarget.

svelte
<Button onclick={() => picker?.pick()}>Choose images</Button>
<FileInput bind:this={picker} accept="image/*" multiple onpick={add} />

Props ​

PropDefaultDescription
acceptThe types it accepts, as the accept of an input
multiplefalseMore than one file
onpickCalled with the chosen files as an array
disabledfalsepick() opens nothing

Contract ​

It renders one hidden file input. onpick is not called when nothing is chosen, and the input is cleared after each choice, so that the same file can be chosen again.

Example ​

FileInput

Released under the Apache-2.0 license.