Skip to content

Input

A basic widget for getting the user input is a text field. Keyboard and mouse can be used for providing or changing data.

When To Use

  • A user input in a form field is needed.
  • A search input is required.

Examples

Basic usage

vue
<template>
  <a-input v-model:value="value" placeholder="Basic usage" />
</template>

<script setup>
import { ref } from 'vue'

const value = ref('')
</script>

Three sizes of Input

vue
<template>
  <div class="components-input-demo-size">
    <a-input v-model:value="value" size="large" placeholder="large size" />
    <a-input v-model:value="value" placeholder="default size" />
    <a-input v-model:value="value" size="small" placeholder="small size" />
  </div>
</template>

<script setup>
import { ref } from 'vue'

const value = ref('')
</script>

<style>
.components-input-demo-size .ant-input {
  width: 200px;
  margin: 0 8px 8px 0;
}
</style>

Pre / Post tab

vue
<template>
  <div>
    <a-input addon-before="Http://" addon-after=".com" default-value="mysite" />
    <br />
    <br />
    <a-input default-value="mysite">
      <template #addonBefore>
        <a-select v-model:value="selectBefore" style="width: 90px">
          <a-select-option value="Http://">Http://</a-select-option>
          <a-select-option value="Https://">Https://</a-select-option>
        </a-select>
      </template>
      <template #addonAfter>
        <a-select v-model:value="selectAfter" style="width: 80px">
          <a-select-option value=".com">.com</a-select-option>
          <a-select-option value=".jp">.jp</a-select-option>
          <a-select-option value=".cn">.cn</a-select-option>
          <a-select-option value=".org">.org</a-select-option>
        </a-select>
      </template>
    </a-input>
    <br />
    <br />
    <a-input default-value="mysite">
      <template #addonAfter>
        <SettingOutlined />
      </template>
    </a-input>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { SettingOutlined } from '@ant-design/icons-vue'

const selectBefore = ref('Http://')
const selectAfter = ref('.com')
</script>
vue
<template>
  <div>
    <a-input-search
      v-model:value="value"
      placeholder="input search text"
      enter-button="Search"
      size="large"
      @search="onSearch"
    />
    <br />
    <br />
    <a-input-search
      v-model:value="value"
      placeholder="input search text"
      @search="onSearch"
    />
    <br />
    <br />
    <a-input-search
      v-model:value="value"
      placeholder="input search text"
      enter-button
      @search="onSearch"
    />
    <br />
    <br />
    <a-input-search
      v-model:value="value"
      placeholder="input search text"
      size="large"
    >
      <template #enterButton>
        <a-button>
          <template #icon><SearchOutlined /></template>
          Custom
        </a-button>
      </template>
    </a-input-search>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { SearchOutlined } from '@ant-design/icons-vue'

const value = ref('')

const onSearch = (searchValue) => {
  console.log('use value', searchValue)
  console.log('or use this.value', value.value)
}
</script>

TextArea

vue
<template>
  <div>
    <a-textarea
      v-model:value="value"
      placeholder="Basic usage"
      :rows="4"
    />
    <br />
    <br />
    <a-textarea
      v-model:value="value"
      placeholder="Autosize height based on content lines"
      auto-size
    />
    <br />
    <br />
    <a-textarea
      v-model:value="value"
      placeholder="Autosize height with minimum and maximum number of lines"
      :auto-size="{ minRows: 2, maxRows: 6 }"
    />
  </div>
</template>

<script setup>
import { ref } from 'vue'

const value = ref('')
</script>

Password box

vue
<template>
  <div>
    <a-input-password
      v-model:value="password"
      placeholder="input password"
    />
    <br />
    <br />
    <a-input-password
      v-model:value="password"
      placeholder="input password"
      :icon-render="visible => (visible ? EyeTwoTone : EyeInvisibleOutlined)"
    />
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { EyeInvisibleOutlined, EyeTwoTone } from '@ant-design/icons-vue'

const password = ref('')
</script>

API

Input

PropertyDescriptionTypeDefaultVersion
addonAfterThe label text displayed after (on the right side of) the input fieldstring | slot-
addonBeforeThe label text displayed before (on the left side of) the input fieldstring | slot-
allowClearIf allow to remove input content with clear iconbooleanfalse
borderedWhether has border stylebooleantrue
defaultValueThe initial input contentstring-
disabledWhether the input is disabledbooleanfalse
idThe ID for inputstring-
maxlengthThe max lengthnumber-
prefixThe prefix icon for the Inputstring | slot-
showCountWhether show text countboolean | objectfalse
sizeThe size of the input box. Note: in the context of a form, the middle size is usedlarge | middle | small-
suffixThe suffix icon for the Inputstring | slot-
typeThe type of input, see: MDN(use Input.TextArea instead of type="textarea")stringtext
value(v-model)The input content valuestring-

Input Events

Events NameDescriptionArgumentsVersion
blurThe callback function that is triggered when Input loses focusfunction(e)
changeCallback when user inputfunction(e)
focusThe callback function that is triggered when Input gets focusfunction(e)
pressEnterThe callback function that is triggered when Enter key is pressedfunction(e)

Input.TextArea

PropertyDescriptionTypeDefaultVersion
allowClearIf allow to remove input content with clear iconbooleanfalse
autoSizeHeight autosize feature, can be set to true | false or an objectboolean | objectfalse
borderedWhether has border stylebooleantrue
defaultValueThe initial input contentstring-
maxlengthThe max lengthnumber-
showCountWhether show text countboolean | objectfalse
value(v-model)The input content valuestring-
PropertyDescriptionTypeDefaultVersion
enterButtonWhether to show an enter button after input. This property conflicts with the addonAfter propertyboolean | slotfalse
loadingSearch box with loadingbooleanfalse

Input.Search Events

Events NameDescriptionArgumentsVersion
searchThe callback function triggered when you click on the search-icon, the clear-icon or press the Enter keyfunction(value, event)

Input.Password

PropertyDescriptionTypeDefaultVersion
iconRenderCustom toggle button(visible) => VNode(visible) => (visible ? <EyeOutlined /> : <EyeInvisibleOutlined />)
visibilityToggleWhether show toggle button or control password visibleboolean | VisibilityToggletrue

VisibilityToggle

PropertyDescriptionTypeDefaultVersion
visibleWhether the password is show or hidebooleanfalse
onVisibleChangeCallback executed when visibility of the password is changedboolean => void-

Released under the MIT License.