Skip to content

Input

TuiInput is the fundamental form input component. It supports various modes such as single-line text, multi-line text, password hiding, and numerical input, while providing extensive prefix and suffix decoration capabilities.

Basic Usage

Text Input

The most basic usage involves using v-model to bind data.

  • Clearable: Set the clearable property to display a one-click clear button.
  • MaxLength: Set maxLength to limit input length and display a character count on the right.
html
<template>
  <div class="demo-gap">
    <TuiInput v-model="val1" placeholder="Please input..." />
    
    <TuiInput v-model="val2" clearable placeholder="Clearable" />
    
    <TuiInput v-model="val3" :maxLength="30" clearable placeholder="30-character limit" />
  </div>
</template>

Password Input

Set the type to 'password'. The component features a built-in password visibility toggle (eye icon).

html
<TuiInput type="password" v-model="password" placeholder="Please enter password" />

Numerical Input (Number)

Set the type to 'number'. This mode supports maximum/minimum limits, step values, and precision control.

  • min/max: Limits the numerical range.
  • step: The step size (the value incremented or decremented when clicking the buttons).
  • precision: Numerical precision (number of decimal places to keep).
html
<template>
  <TuiInput type="number" v-model="num1" />
  
  <TuiInput type="number" :min="0" :max="10" v-model="num2" />
  
  <TuiInput type="number" :step="0.05" :precision="2" v-model="num3" />
</template>

Multi-line Text (Textarea)

Set the type to 'textarea'.

  • rows: Sets the default number of rows.
  • autosize: Whether to automatically adjust the height based on content (adaptive).
html
<TuiInput 
  type="textarea" 
  :rows="3" 
  :maxLength="200" 
  v-model="desc" 
  placeholder="Please enter description..." 
/>

Decoration and Combination

Icons

Three icon position properties are provided:

  • icon: Default suffix icon (commonly used for search).
  • prefixIcon: Header icon.
  • suffixIcon: Suffix icon (similar position to icon, but with clearer semantics).
html
<template>
  <TuiInput icon="tui-icon ti-search" v-model="search" />
  
  <TuiInput 
    prefixIcon="tui-icon ti-user" 
    suffixIcon="tui-icon ti-info-circle" 
    v-model="user" 
  />
</template>

Composite Slots (Slots)

Through the prefix and suffix slots, more complex elements such as labels, buttons, or dropdown menus can be embedded before or after the input box.

html
<template>
  <TuiInput v-model="url">
    <template #prefix>Http://</template>
    <template #suffix>.com</template>
  </TuiInput>

  <TuiInput v-model="keyword" placeholder="Search...">
    <template #suffix>
      <TuiButton type="primary" size="small">Search</TuiButton>
    </template>
  </TuiInput>
</template>

Status and Size

  • Disabled: Disabled state; not editable and styled in gray.
  • Readonly: Read-only state; not editable but maintains original styling (no border or light background).
  • Size: Supports large, default, and small.
html
<template>
  <TuiInput disabled value="Disabled State" />
  <TuiInput readonly value="Read-only State" />
  
  <div class="demo-gap">
    <TuiInput size="large" placeholder="Large" />
    <TuiInput size="default" placeholder="Default" />
    <TuiInput size="small" placeholder="Small" />
  </div>
</template>

API Reference

Props

PropertyTypeDefaultDescription
modelValueString/Number-Bound value.
typeString'text'Type. Options: text, textarea, password, number.
sizeString'default'Size. Options: large, default, small.
placeholderString-Input placeholder text.
clearableBooleanfalseWhether it is clearable.
disabledBooleanfalseWhether it is disabled.
readonlyBooleanfalseWhether it is read-only.
maxLengthNumber/String-Maximum input length.
iconString-Suffix icon class name.
prefixIconString-Header icon class name.
suffixIconString-Suffix icon class name.
rowsNumber3(Textarea) Number of rows.
autosizeBooleanfalse(Textarea) Whether to adapt height automatically.
minNumber-100(Number) Minimum value.
maxNumberMAX_SAFE(Number) Maximum value.
stepNumber1(Number) Step size.
precisionNumber0(Number) Numerical precision.
formatterFunction-Content formatting function.
autocompleteString'off'Native autocomplete attribute.

Events

Event NameDescriptionCallback Parameters
update:modelValueTriggered when the bound value changes.(value)
inputTriggered during input.(value)
changeTriggered on blur or Enter (only if the value changed).(value)
focusTriggered when gaining focus.(event)
blurTriggered when losing focus.(event)
clearTriggered when the clear button is clicked.-

Slots

Slot NameDescription
prefixHeader content of the input box (text or component).
suffixSuffix content of the input box (text or component).

Released under the MIT License.