page FileInputcomponent { seo { title = "FileInput component" description = "Theme-aware, responsive file input component." } view {
W WRNexusJS
forms component

FileInput

Theme-aware, responsive file input component.

@wrnexus/ui 0.5.021 props0 slots7 events

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

PropTypeRequirementDefault
sizestringOptional"default"
colorstringOptional"primary"
idstringOptional""
namestringOptional""
labelstringOptional"File"
hiddenLabelbooleanOptionalfalse
placeholderstringOptional"Choose a file"
valuestringOptional""
iconstringOptional"icon-[lucide--upload]"
iconPositionstringOptional"start"
acceptstringOptional""
multiplebooleanOptionalfalse
helperTextstringOptional""
cornerHintstringOptional""
errorstringOptional""
inlinebooleanOptionalfalse
variantstringOptional"normal"
readonlybooleanOptionalfalse
disabledbooleanOptionalfalse
requiredbooleanOptionalfalse
classstringOptional""

Slots

This component does not declare a slot.

Events

  • input
  • change
  • focus
  • blur
  • select
  • clear
  • invalid

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>
    }
}
} }