FileInput
Theme-aware, responsive file input component.
Usage
Components are auto-discovered. Use the component directly in any .wrn view:
<FileInput
size="default"
color="primary"
id="id"
name="name"
label="File"
/>Legacy mount name: data-component="FileInput".
Props and attributes
| Prop | Type | Requirement | Default |
|---|---|---|---|
size | string | Optional | "default" |
color | string | Optional | "primary" |
id | string | Optional | "" |
name | string | Optional | "" |
label | string | Optional | "File" |
hiddenLabel | boolean | Optional | false |
placeholder | string | Optional | "Choose a file" |
value | string | Optional | "" |
icon | string | Optional | "icon-[lucide--upload]" |
iconPosition | string | Optional | "start" |
accept | string | Optional | "" |
multiple | boolean | Optional | false |
helperText | string | Optional | "" |
cornerHint | string | Optional | "" |
error | string | Optional | "" |
inline | boolean | Optional | false |
variant | string | Optional | "normal" |
readonly | boolean | Optional | false |
disabled | boolean | Optional | false |
required | boolean | Optional | false |
class | string | Optional | "" |
Slots
This component does not declare a slot.
Events
inputchangefocusblurselectclearinvalid
Source contract
Installed source: components/FileInput.wrn
component FileInput {
props {
@event input = function
@event change = function
@event focus = function
@event blur = function
@event select = function
@event clear = function
@event invalid = function
size = "default"
color = "primary"
id = ""
name = ""
label = "File"
hiddenLabel = false
placeholder = "Choose a file"
value = ""
icon = "icon-[lucide--upload]"
iconPosition = "start"
accept = ""
multiple = false
helperText = ""
cornerHint = ""
error = ""
inline = false
variant = "normal"
readonly = false
disabled = false
required = false
class = ""
}
state selectedName = ""
functions {
function handleChange(sourceEvent) {
sourceEvent.stopPropagation()
selectedName = sourceEvent.currentTarget.files && sourceEvent.currentTarget.files.length ? sourceEvent.currentTarget.files[0].name : ""
$emit("input", { files: sourceEvent.currentTarget.files, name: name, sourceEvent: sourceEvent })
$emit("change", { files: sourceEvent.currentTarget.files, name: name, sourceEvent: sourceEvent })
if (selectedName) $emit("select", { files: sourceEvent.currentTarget.files, name: name, sourceEvent: sourceEvent })
else $emit("clear", { name: name, sourceEvent: sourceEvent })
}
function emitField(nameEvent, sourceEvent) { sourceEvent.stopPropagation(); $emit(nameEvent, { name: name, sourceEvent: sourceEvent }) }
function preventReadonly(sourceEvent) { if (readonly) sourceEvent.preventDefault() }
}
view {
<div {...attrs} class="wire-next wire-next--color-{color} wire-next--size-{size} wire-next--field wire-next--file-input {class}" data-variant="{variant}" data-inline="{inline}" data-invalid="{error ? 'true' : 'false'}">
<div class="wire-next__field-heading">
<label class="{hiddenLabel ? 'wire-next__sr-only' : ''}" for="{id || name}">{label}</label>{#if cornerHint}<span class="wire-next__field-hint">{cornerHint}</span>{/if}</div>
<div class="wire-next__file-control" data-icon-position="{iconPosition}">{#if icon}<span class="{icon}" aria-hidden="true">
</span>{/if}<span>{selectedName || value || placeholder}</span>
<input id="{id || name}" type="file" name="{name}" accept="{accept}" multiple="{multiple}" disabled="{disabled}" required="{required}" aria-readonly="{readonly}" aria-invalid="{error ? 'true' : 'false'}" @click="preventReadonly(event)" @input="handleChange(event)" @change="handleChange(event)" @focus="emitField('focus', event)" @blur="emitField('blur', event)" @invalid="emitField('invalid', event)" />
</div>
{#if helperText}<small class="wire-next__field-help">{helperText}</small>{/if}<small class="wire-next__field-error" data-error="{name}">{error}</small>
</div>
}
}