File Input Showcase

Example

Drag and drop file here or

Example 2

Drag and drop file here or

Example 3

Component Documentation

Component Name

FileInput

Builder Function Name

create_file_input_manager

Description

allows users to select or drop files; optionally multiple, with drag-and-drop area and custom validation

Use like example

Config

PropertyTypeDefaultDescription
valany

the current file or array of files selected

labelstring

label for the file input

namestring

file

the name attribute for the underlying file input element

is_requiredboolean

false

marks the input as required

is_read_onlyboolean

false

makes 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

false

if true, the file input accepts multiple files

is_disabledboolean

false

disables file input if true

border_radiusnumber

2

border radius in rem for the drop zone

heightstring

height (e.g., '200px') of the drop zone; if null, auto-sizes

icon_colorstring

var(--primary-t)

color for the drop zone icon

border_colorstring

aabbccff

hex color used for the dashed border

is_drop_zoneboolean

true

if true, enables drag-and-drop area

is_hide_drop_zone_if_fileboolean

true

if true and a file is already selected, hides the drop zone

mlnumber

0

margin-left in rem

mrnumber

0

margin-right in rem

mtnumber

0

margin-top in rem

mbnumber

0

margin-bottom in rem

select_file_button_textstring

custom text for the 'select file' button

on_get_filefunction

callback when a file is selected or dropped; receives val

on_clear_filesfunction

callback when files are cleared by the user

Methods

MethodDescriptionParametersReturns
init

initializes the file input manager and supporting managers (icon, buttons, etc.)

config: object

void
get_file

handles the <input type='file'> onchange event, sets val, and calls on_get_file if provided

e: event

void
drop_handler

handles drag-and-drop events, sets val for accepted file types, populates error_message otherwise

ev: event

void
clear_files

clears the currently selected file(s) and calls on_clear_files if provided

No Params

void

Returned Properties

PropertyTypeDescription
idstring

unique id for this file input instance

valany

the currently selected file or an array of files

namestring

the name attribute of the underlying file input

labelstring

label text displayed above the file input

is_requiredboolean

true if the field is required

is_read_onlyboolean

true if file input is read-only

acceptarray

file type strings that are acceptable

is_multiselectboolean

true if multiple files can be selected

is_disabledboolean

if true, the file input is disabled

border_radiusnumber

border radius (rem) for the drop zone

heightstring

custom height (e.g. '200px') for the drop zone

icon_colorstring

the color used for the file drop icon

border_colorstring

the color used for the dashed border

is_drop_zoneboolean

enables drag-and-drop if true

is_hide_drop_zone_if_fileboolean

hides drop zone if a file is already selected

mlnumber

margin-left in rem

mrnumber

margin-right in rem

mtnumber

margin-top in rem

mbnumber

margin-bottom in rem

select_file_button_textstring

custom text for the 'select file' button

error_messagestring

shows errors if a dropped file does not match accepted types, etc.

svg_bgstring

background-image dataurl for the dashed border overlay

error_button_managerobject

button manager to dismiss the displayed error message

clear_files_button_managerobject

button manager to clear the currently selected file(s)

file_drop_icon_managerobject

icon manager for the displayed file drop icon

icon
Sponsored byContibase