Skip to content

Input Component

This component is an input box that allows you to quickly implement features such as form validation, content input, and dropdown selection.

📌 Platform Compatibility

APP(vue)H5WeChat Mini ProgramAlipay Mini Program

🏯 Basic Usage Examples

  • Use type to set the type of the input box, defaults to text
  • Use placeholder to set the placeholder shown when the input box is empty
  • Use border to configure whether to display the input box border
  • Bind the @change event
html
<!-- 全局使用 -->
<hy-input
    text="月落"
    placeholder="请输入内容"
    border="surround"
    v-model="value"
    @change="change"
></hy-input>
ts
import { ref } from 'vue';

const value = ref('');

Clearable Input

Setting clearable to true adds a clear button after the input box.

html
<hy-input clearable></hy-input>

Input Box Types

  • text - Text input keyboard.
  • number - Numeric input keyboard; floating-point numbers can be entered on app-vue, while only integers can be entered on app-nvue and mini program platforms.
  • idcard - ID card input keyboard; available on WeChat, Alipay, Baidu, and QQ Mini Programs.
  • digit - Numeric keyboard with decimal point; available on App nvue pages, WeChat, Alipay, Baidu, Toutiao, and QQ Mini Programs.
  • password - Equivalent to setting password to true
html
<hy-input type="text"></hy-input>
<hy-input type="number"></hy-input>
<hy-input type="idcard"></hy-input>
<hy-input type="digit"></hy-input>
<hy-input type="password"></hy-input>

Input Box Shape

  • Setting shape to circle gives you an input box with semicircular ends.
  • Setting shape to square gives you a square input box.
html
<hy-input shape="circle"></hy-input>
<hy-input shape="square"></hy-input>

Input Box Border

  • Setting the border property to surround gives you a border on all four sides
  • Setting the border property to none gives you no border
  • Setting the border property to bottom turns it into an underline
html
<hy-input border="surround"></hy-input>
<hy-input border="none"></hy-input>
<hy-input border="bottom"></hy-input>

Prefix and Suffix Icons

  • Configure the prefix icon via prefixIcon with freely customizable style information.
  • Configure the suffix icon via suffixIcon with freely customizable style information.
html
<hy-input
    placeholder="前置图标"
    :prefixIcon="{
            name: 'search'
        }"
></hy-input>
<hy-input
    placeholder="后置图标"
    :suffixIcon="{
            name: 'map-fill'
        }"
    suffixIconStyle="color: #909399"
></hy-input>

Prefix and Suffix Slots

Set slot to prefix or suffix to specify the prefix or suffix slot for custom content or icons.

html
<template>
    <!-- 前置插槽 -->
    <hy-input placeholder="前置插槽">
        <template #prefix>
            <hy-icon :name="IconConfig.search"></hy-icon>
        </template>
    </hy-input>

    <!-- 后置插槽 -->
    <hy-input placeholder="前置插槽">
        <template #suffix>
            <hy-button text="获取验证码"></hy-button>
        </template>
    </hy-input>
</template>

<script setup lang="ts"></script>

API

Input Props

PropDescriptionTypeDefault
modelValueThe value of the inputstring-
typeType of the input box[1]number|idcard|digit| password|texttext
disabledWhether to disable the input boxbooleanfalse
disabledColorBackground color in the disabled statestring-
clearableWhether to show the clear controlbooleanfalse
passwordWhether it is a password typebooleanfalse
maxlengthMaximum input length; set to -1 for unlimited length (Note: Alipay does not support -1, so you need to set it to any other value)number140
placeholderPlaceholder shown when the input box is emptystring-
placeholderClassSpecifies the style class of the placeholder; note that when scoped is used in the style of the page or component, you need to write /deep/ before the class namestringinput-placeholder
placeholderStyleSpecifies the style of the placeholderCSSProperties-
showWordLimitWhether to show the input word count; only effective when type ="text" or type ="textarea"booleanfalse
confirmTypeSets the text of the button in the bottom-right corner; see the uni-app documentation for compatibility detailsstringdone
confirmHoldWhether to keep the keyboard from collapsing when the button in the bottom-right corner of the keyboard is tapped; not effective on H5booleanfalse
holdKeyboardWhen focused, the keyboard does not collapse when the page is tapped; effective on WeChat Mini Programbooleanfalse
focusAutomatically gets focus; on the H5 platform, whether it can focus and whether the soft keyboard pops up along with it depends on the implementation of the current browser itself.booleanfalse
autoBlurWhether to automatically lose focus when the keyboard collapses; currently only effective on App 3.0.0+booleanfalse
disableDefaultPaddingWhether to remove the default padding on iOS; only effective on WeChat Mini Program with type=textareabooleanfalse
cursorSpecifies the cursor position when focusednumber-1
cursorSpacingDistance between the bottom of the input box and the keyboard when the input box is focusednumber30
selectionStartCursor start position; effective with auto focus, must be used together with selection-endnumber-1
selectionEndCursor end position; effective with auto focus, must be used together with selection-startnumber-1
adjustPositionWhether the page is automatically pushed up when the keyboard pops upbooleantrue
inputAlignAlignment of the input box contentstringleft
fontSizeFont size of the input box; numbers default to pxstring | number15px
colorFont color of the input boxstring-
prefixIconPrefix icon of the input box; see Icon API for configuration detailsHyIconProps-
suffixIconSuffix icon of the input box; see Icon API for configuration detailsHyIconProps-
borderBorder type[2]surround|bottom|nonesurround
readonlyWhether it is read-only; the difference from disabled is that disabled grays out the component, while readonly does notbooleanfalse
shapeShape of the input box[3]circle|squaresquare
formatterInput filtering or formatting function (for WeChat Mini Program compatibility, it can only be set via the setFormatter method)function | nullnull
customStyleCustom external styles to be appliedCSSProperties-
customClassCustom external class namestring-

Events

Event NameDescriptionCallback Parameters
blurTriggered when the input box loses focusvalue: content value
focusTriggered when the input box gains focus-
confirmTriggered when the done button is tappedvalue: content value
keyboardheightchangeTriggered when the keyboard height changesevent
update:modelValueTriggered when the content changesvalue: content value
changeTriggered when the content changesvalue: content value
clearTapped to clear the content-
onPrefixTriggered when the prefix is tapped-
onSuffixTriggered when the suffix is tapped-

Slots

Slot NameDescription
prefixPrefix content of the input box
suffixSuffix content of the input box
03:29

  1. text: text input content; number: numeric input keyboard, floating-point numbers can be entered on app-vue, while only integers can be entered on app-nvue and mini program platforms; idcard: ID card input keyboard, available on WeChat, Alipay, Baidu, and QQ Mini Programs; digit: numeric keyboard with decimal point, available on App nvue pages, WeChat, Alipay, Baidu, Toutiao, and QQ Mini Programs; password: password input box ↩︎

  2. surround: border on all four sides; bottom: border on the bottom; none: no border ↩︎

  3. circle: semicircular ends; square: square with rounded corners ↩︎