Skip to content

Input Component ​

This component is an input box. With it, you can quickly implement features such as form validation, content input, and dropdown selection.

📌 Platform Differences ​

APP(vue)H5WeChat Mini ProgramAlipay Mini Program
✔✔✔✔

🏯 Basic Usage Example ​

  • Set the input type via type; the default is text
  • Set the placeholder displayed when the input is empty via placeholder
  • Use border to configure whether the input border is shown
  • Bind the @change event
html
<!-- Global usage -->
<hy-input
    text="月落"
    placeholder="Please enter content"
    border="surround"
    v-model="value"
    @change="change"
></hy-input>
ts
import { ref } from 'vue';

const value = ref('');

Clearable ​

Set clearable to true to add a clear button at the end of the input box.

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

Input Types ​

  • text - Text input keyboard.
  • number - Numeric input keyboard. On app-vue, floating-point numbers can be entered; on app-nvue and mini program platforms, only integers can be entered.
  • idcard - ID card input keyboard, available on WeChat, Alipay, Baidu, and QQ mini programs.
  • digit - Numeric keyboard with a decimal point, available on App nvue pages and 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 Shape ​

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

Input Border ​

  • Set the border property to surround for a border on all four sides
  • Set the border property to none for no border
  • Set the border property to bottom to turn 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 ​

  • Set prefixIcon to configure the prefix icon, with freely customizable style information.
  • Set suffixIcon to configure the suffix icon, with freely customizable style information.
html
<hy-input
    placeholder="Prefix icon"
    :prefixIcon="{
            name: 'search'
        }"
></hy-input>
<hy-input
    placeholder="Suffix icon"
    :suffixIcon="{
            name: 'map-fill'
        }"
    suffixIconStyle="color: #909399"
></hy-input>

Prefix and Suffix Slots ​

Set slot to prefix or suffix to designate prefix/suffix slots for custom content or icons

html
<template>
    <!-- Prefix slot -->
    <hy-input placeholder="Prefix slot">
        <template #prefix>
            <hy-icon :name="IconConfig.search"></hy-icon>
        </template>
    </hy-input>

    <!-- Suffix slot -->
    <hy-input placeholder="Prefix slot">
        <template #suffix>
            <hy-button text="Get verification code"></hy-button>
        </template>
    </hy-input>
</template>

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

API ​

Input Props ​

PropDescriptionTypeDefault
modelValueThe entered valuestring-
typeInput box type[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. When set to -1, there is no limit on the maximum length (Note: Alipay does not support -1, so any other value must be set)number140
placeholderPlaceholder shown when the input box is emptystring-
placeholderClassSpecifies the style class of the placeholder. Note that when scoped is used in the page or component style, /deep/ must be prepended to the class namestringinput-placeholder
placeholderStyleSpecifies the style of the placeholderCSSProperties-
showWordLimitWhether to show the 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 bottom-right keyboard button is tapped. Not effective on H5booleanfalse
holdKeyboardWhen focused, the keyboard will not collapse when the page is tapped. Effective on WeChat Mini Programbooleanfalse
focusAutomatically gets focus. On the H5 platform, whether focusing works and whether the soft keyboard pops up depend on the current browser's implementation.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 and when type=textareabooleanfalse
cursorSpecifies the cursor position when focusednumber-1
cursorSpacingDistance between the bottom of the input box and the keyboard when focusednumber30
selectionStartCursor start position. Effective when auto-focused; must be used together with selection-endnumber-1
selectionEndCursor end position. Effective when auto-focused; must be used together with selection-startnumber-1
adjustPositionWhether to automatically push the page up when the keyboard pops upbooleantrue
inputAlignAlignment of the input box contentstringleft
fontSizeFont size of the input box. Numbers use px as the default unitstring | 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
shapeInput box shape[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 ​

EventDescriptionCallback Parameter
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
clearTriggered when tapping to clear the content-
onPrefixTriggered when the prefix is tapped-
onSuffixTriggered when the suffix is tapped-

Slots ​

SlotDescription
prefixContent in front of the input box
suffixContent after the input box

CSS Variables ​

VariableDescriptionDefault
--hy-input-radius-squareSquare corner radius4px
--hy-input-radius-circleCapsule corner radiusFollows --hy-radius-semicircle (100px)
--hy-input-heightInput box height24px
--hy-input-line-heightLine height26px
--hy-input-font-sizeFont size15px
--hy-input-clear-sizeClear button size20px
--hy-input-colorInput text colorFollows --hy-text-color
--hy-input-placeholder-colorPlaceholder colorFollows --hy-text-color--placeholder
--hy-input-disabled-colorDisabled text colorFollows --hy-text-color--disabled
--hy-input-clear-radiusClear button corner radiusFollows --hy-radius-semicircle (100px)
--hy-input-borderBorderFollows --hy-border-line
12:33
battery

  1. text: Text input; number: Numeric input keyboard — floating-point numbers can be entered under app-vue, while only integers can be entered under app-nvue and mini program platforms; idcard: ID card input keyboard, available on WeChat, Alipay, Baidu, and QQ mini programs; digit: Numeric keyboard with a decimal point, available on App nvue pages and 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 on both ends; square: Square with rounded corners ↩︎