Live preview

Interactive example

Loading example…

Usage

Import the component and its manager, then make it your own.

ComponentFileInput
Managercreate_file_input_manager

svelte

<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { FileInput, create_file_input_manager } from "sveltekit-ui"

  let file_name = $state("")

  const manager = create_file_input_manager({
    label: "Choose a document",
    accept: ["application/pdf", "text/plain"],
    is_multiselect: false,
    on_get_file: (file) => { file_name = file.name },
    on_clear_files: () => { file_name = "" },
  })
</script>

<FileInput {manager} />
{#if file_name}<p role="status">Selected: {file_name}</p>{/if}

API reference

Configure the manager, call its methods, and read its reactive state.

21 entries in configuration

PropertyTypeDefaultDescription
valany nullthe current file or array of files selected
labelstring nulllabel for the file input
namestring filethe name attribute for the underlying file input element
is_requiredboolean falsemarks the input as required
is_read_onlyboolean falsemakes the file input read-only if true
acceptarray ["image/png","image/jpeg","image/webp","image/gif","image/avif","image/svg+xml","application/pdf","video/mp4","audio/mpeg","audio/aac","application/json"]the accepted file types
is_multiselectboolean falseif true, the file input accepts multiple files
is_disabledboolean falsedisables file input if true
border_radiusnumber 2border radius in rem for the drop zone
heightstring nullheight (e.g., '200px') of the drop zone; if null, auto-sizes
icon_colorstring var(--primary-t)color for the drop zone icon
border_colorstring aabbccffhex color used for the dashed border
is_drop_zoneboolean trueif true, enables drag-and-drop area
is_hide_drop_zone_if_fileboolean trueif true and a file is already selected, hides the drop zone
mlnumber 0margin-left in rem
mrnumber 0margin-right in rem
mtnumber 0margin-top in rem
mbnumber 0margin-bottom in rem
select_file_button_textstring nullcustom text for the 'select file' button
on_get_filefunction nullcallback when a file is selected or dropped; receives val
on_clear_filesfunction nullcallback when files are cleared by the user