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

Input

Theme-aware, responsive input component.

@wrnexus/ui 0.5.028 props0 slots7 events

Usage

Components are auto-discovered. Use the component directly in any .wrn view:

<Input
  size="default"
  color="primary"
  id="id"
  name="name"
  label="Input"
/>

Legacy mount name: data-component="Input".

Props and attributes

PropTypeRequirementDefault
sizestringOptional"default"
colorstringOptional"primary"
idstringOptional""
namestringOptional""
labelstringOptional"Input"
hiddenLabelbooleanOptionalfalse
placeholderstringOptional""
valuestringOptional""
typestringOptional"text"
variantstringOptional"normal"
iconstringOptional""
iconPositionstringOptional"start"
helperTextstringOptional""
cornerHintstringOptional""
errorstringOptional""
inlinebooleanOptionalfalse
readonlybooleanOptionalfalse
disabledbooleanOptionalfalse
requiredbooleanOptionalfalse
autocompletestringOptional""
inputmodestringOptional""
minlengthstringOptional""
maxlengthstringOptional""
patternstringOptional""
minstringOptional""
maxstringOptional""
stepstringOptional""
classstringOptional""

Slots

This component does not declare a slot.

Events

  • input
  • change
  • focus
  • blur
  • invalid
  • keydown
  • keyup

Source contract

Installed source: components/Input.wrn

component Input {
  props {
    @event input = function
    @event change = function
    @event focus = function
    @event blur = function
    @event invalid = function
    @event keydown = function
    @event keyup = function
    size = "default"
    color = "primary"
    id = ""
    name = ""
    label = "Input"
    hiddenLabel = false
    placeholder = ""
    value = ""
    type = "text"
    variant = "normal"
    icon = ""
    iconPosition = "start"
    helperText = ""
    cornerHint = ""
    error = ""
    inline = false
    readonly = false
    disabled = false
    required = false
    autocomplete = ""
    inputmode = ""
    minlength = ""
    maxlength = ""
    pattern = ""
    min = ""
    max = ""
    step = ""
    class = ""
  }
  functions {
    function detail(sourceEvent) {
      return { value: sourceEvent.currentTarget.value, name: name, sourceEvent: sourceEvent }
    }
    function handleInput(sourceEvent) { sourceEvent.stopPropagation(); $emit("input", detail(sourceEvent)) }
    function handleChange(sourceEvent) { sourceEvent.stopPropagation(); $emit("change", detail(sourceEvent)) }
    function handleFocus(sourceEvent) { sourceEvent.stopPropagation(); $emit("focus", detail(sourceEvent)) }
    function handleBlur(sourceEvent) { sourceEvent.stopPropagation(); $emit("blur", detail(sourceEvent)) }
    function handleInvalid(sourceEvent) { sourceEvent.stopPropagation(); $emit("invalid", { value: sourceEvent.currentTarget.value, name: name, message: sourceEvent.currentTarget.validationMessage, sourceEvent: sourceEvent }) }
    function handleKeydown(sourceEvent) { sourceEvent.stopPropagation(); $emit("keydown", { key: sourceEvent.key, value: sourceEvent.currentTarget.value, name: name, sourceEvent: sourceEvent }) }
    function handleKeyup(sourceEvent) { sourceEvent.stopPropagation(); $emit("keyup", { key: sourceEvent.key, value: sourceEvent.currentTarget.value, name: name, sourceEvent: sourceEvent }) }
  }
  view {
        <div {...attrs} class="wire-next wire-next--color-{color} wire-next--size-{size} wire-next--field wire-next--input {class}" data-variant="{variant}" data-inline="{inline}" data-floating="{variant === 'floating'}" 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__field-control" data-icon-position="{iconPosition}">
        {#if icon}<span class="{icon} wire-next__field-icon" aria-hidden="true">
        </span>{/if}
        <input
          id="{id || name}"
          type="{type}"
          name="{name}"
          value="{value}"
          placeholder="{variant === 'floating' ? ' ' : placeholder}"
          readonly="{readonly}"
          disabled="{disabled}"
          required="{required}"
          autocomplete="{autocomplete}"
          inputmode="{inputmode}"
          minlength="{minlength}"
          maxlength="{maxlength}"
          pattern="{pattern}"
          min="{min}"
          max="{max}"
          step="{step}"
          aria-invalid="{error ? 'true' : 'false'}"
          aria-describedby="{error ? (id || name) + '-error' : (helperText ? (id || name) + '-help' : '')}"
          @input="handleInput(event)"
          @change="handleChange(event)"
          @focus="handleFocus(event)"
          @blur="handleBlur(event)"
          @invalid="handleInvalid(event)"
          @keydown="handleKeydown(event)"
          @keyup="handleKeyup(event)"
        />
        {#if variant === "floating"}<span class="wire-next__field-floating-label">{label}</span>{/if}
      </div>
      {#if helperText}<small id="{(id || name) + '-help'}" class="wire-next__field-help">{helperText}</small>{/if}
      <small id="{(id || name) + '-error'}" class="wire-next__field-error" data-error="{name}">{error}</small>
        </div>
    }
}
} }