Skip to content

Input ​

Input component encapsulation, works better with z-form.

Basic Usage ​

Basic usage of z-input.

<script lang="ts" setup>
import { ref } from 'vue'

const val = ref('')

function handleInputChange(val: string) {
  // eslint-disable-next-line no-console
  console.log(val)
}
</script>

<template>
  <z-input v-model="val" clearable placeholder="Please enter" @change="handleInputChange" />
</template>

Input with Icon ​

You can simply use prefix-icon and suffix-icon attributes. Additionally, using prefix and suffix to pass functions or slots can achieve the same effect.

<script lang="ts" setup>
import { h, ref, resolveComponent } from 'vue'

const val = ref('')
const value = ref('')

const setPrefixIcon = () => {
  return h(resolveComponent('el-icon'), {}, () => h(resolveComponent('i-search')))
}

const setSuffixIcon = () => {
  return h(resolveComponent('el-icon'), {}, () => h(resolveComponent('i-calendar')))
}
</script>

<template>
  <z-input v-model="val" clearable placeholder="Please enter" prefix-icon="i-search" suffix-icon="i-calendar" class="mb-2" />
  <z-input v-model="value" clearable placeholder="Please enter" :prefix="setPrefixIcon" :suffix="setSuffixIcon" class="mb-2" />
  <z-input v-model="value" clearable placeholder="Please enter">
    <template #prefix>
      <el-icon>
        <i-search />
      </el-icon>
    </template>
    <template #suffix>
      <el-icon>
        <i-calendar />
      </el-icon>
    </template>
  </z-input>
</template>

Composite Input ​

You can simply use append and prepend attributes. Additionally, using append and prepend to pass functions or slots can achieve the same effect.

<script lang="ts" setup>
import { h, ref, resolveComponent } from 'vue'

const val = ref('')
const value = ref('')

const setAppend = () => {
  return h(resolveComponent('el-icon'), {}, () => h(resolveComponent('i-search')))
}

const setPrepend = () => {
  return h(resolveComponent('el-icon'), {}, () => h(resolveComponent('i-calendar')))
}
</script>

<template>
  <z-input v-model="val" clearable placeholder="Please enter" prepend="Http://" append=".com" class="mb-2" />
  <z-input v-model="value" clearable placeholder="Please enter" :append="setAppend" :prepend="setPrepend" class="mb-2" />
  <z-input v-model="value" clearable placeholder="Please enter">
    <template #append>
      <span>.com</span>
    </template>
    <template #prepend>
      <span>Http://</span>
    </template>
  </z-input>
</template>

z-input Attributes ​

AttributeDescriptionTypeDefault
typeTypestring native input typestext
model-value / v-modelBinding valuestring / number—
prependInput prepend contentstring / () => VNode—
appendInput append contentstring / () => VNode—
prefixInput prefix contentstring / () => VNode—
suffixInput suffix contentstring / ()=> VNode—
maxlengthMaximum input lengthstring / number—
minlengthNative attribute, minimum input lengthnumber—
show-word-limitWhether to show word count, only works when type is 'text' or 'textarea'booleanboolean
placeholderInput placeholder textstring—
clearableWhether to show clear button, only works when type is not textareabooleanfalse
formatterSpecifies the format of input value. (Only works when type is "text")Function—
parserSpecifies the value extracted from formatter input. (Only works when type is "text")Function—
show-passwordWhether to show toggle password iconbooleanfalse
disabledWhether disabledbooleanfalse
sizeInput size, only works when type is not 'textarea'enum—
prefix-iconCustom prefix iconstring / Component—
suffix-iconCustom suffix iconstring / Component—
rowsNumber of input rows, only works when type is 'textarea'numbernumber
autosizeWhether textarea height adapts automatically, only works when type is 'textarea'. Can accept an object, e.g: { minRows: 2, maxRows: 6 }boolean / objectfalse
autocompleteNative autocomplete attributestringoff
nameEquivalent to native input name attributestring—
readonlyNative readonly attribute, whether readonlybooleanfalse
maxNative max attribute, sets maximum value——
minNative attribute, sets minimum value——
stepNative attribute, sets legal number intervals for input field——
resizeControls whether user can resizeenum—
autofocusNative attribute, auto focusbooleanfalse
formNative attributestring—
tabindexInput tabindexstring / number—
validate-eventWhether to trigger form validation when inputbooleantrue
input-styleStyle of input element or textarea elementstring / object{}

z-input Events ​

Event NameDescriptionType
blurTriggered when selector input loses focusFunction
focusTriggered when selector input gains focusFunction
changeOnly triggered when modelValue changes, when input loses focus or user presses EnterFunction
inputTriggered when Input value changesFunction
clearTriggered when clicking clear button generated by clearable attributeFunction

z-input Methods ​

NameDescriptionType
blurMake input lose focusFunction
clearClear input valueFunction
focusMake input gain focusFunction
resizeTextareaResize textareaFunction
selectSelect text in inputFunction

z-input Slots ​

Slot NameDescriptionSubtags
prependInput prepend content—
appendInput append content—
prefixInput prefix content—
suffixInput suffix content—

Released under the MIT License.