Skip to content

Input

Users can enter content in the text box.

Component Type

Basic Usage

Bind the input value through v-model, and set the placeholder prompt through placeholder.

html
<wd-input v-model="value" type="text" placeholder="Please enter username" @input="handleInput" />
typescript
import { ref } from 'vue'

const value = ref('')

function handleInput(event) {
  console.log(event)
}

Number Type

After setting type to number, only numbers are allowed to be entered.

html
<wd-input v-model="value" type="number" />

Component State

Disabled

Input is not allowed after setting disabled.

html
<wd-input v-model="value" disabled />

Readonly

After setting readonly, editing is not allowed, but the display style will still be retained.

html
<wd-input v-model="value" readonly />

Error State

After setting error, the input content will be displayed in an error state.

html
<wd-input v-model="value" placeholder="Please enter username" error />

Component Variant

Clear Button

After setting clearable, the clear button is displayed when the clearable condition is met.

html
<wd-input v-model="value" clearable @clear="handleClear" />

Show Clear Button When Focused

Control to only display the clear button when the input box is focused and has a value through clear-trigger="focus".

Note

Alipay Mini Program does not support clear-trigger temporarily, and the clear button cannot be clicked in some scenarios. Please refer to issue.

html
<wd-input v-model="value" clear-trigger="focus" clearable />

Do Not Auto Focus After Clear

Control whether to refocus after clicking the clear button through focus-when-clear.

html
<wd-input v-model="value" :focus-when-clear="false" clearable />

Password Input Box

After setting show-password, the password visibility state can be toggled.

html
<wd-input v-model="value" clearable show-password />

Content Form

Front and Back Icons

Set the front and back icons through prefix-icon and suffix-icon. For icon names, please refer to Icon.

html
<wd-input
  v-model="value"
  prefix-icon="sound"
  suffix-icon="send"
  clearable
  @clickprefixicon="handlePrefixClick"
  @clicksuffixicon="handleSuffixClick"
/>

Suffix Slot

Customize the suffix content through the suffix slot.

html
<wd-input v-model="value" clearable placeholder="Please enter">
  <template #suffix>
    <wd-button size="small">Get Verification Code</wd-button>
  </template>
</wd-input>

Component Style

Character Limit

After setting maxlength, the current character count can be displayed through show-word-limit.

html
<wd-input v-model="value" :maxlength="20" show-word-limit />

Compact Layout

After setting compact, the default padding and background of the input box will be removed, suitable for use with wd-cell or wd-form-item.

html
<wd-input
  v-model="price"
  compact
  placeholder="Please enter price"
  custom-style="display: inline-block; width: 70px; vertical-align: middle;"
/>
<text style="margin-left: 8px;">Yuan</text>

Special Usage

Combined with Form Usage

For the current form scenario, it is recommended to use wd-form and wd-form-item to carry the title, required state, and validation prompt. wd-input is only responsible for the input capability.

html
<wd-form :model="formData" border title-width="98px">
  <wd-form-item title="Basic Usage" prop="basic">
    <wd-input v-model="formData.basic" placeholder="Please enter" compact />
  </wd-form-item>

  <wd-form-item title="Custom Slot" prop="slot" center>
    <wd-input v-model="formData.slot" placeholder="Please enter" clearable compact>
      <template #suffix>
        <wd-button size="small">Get Verification Code</wd-button>
      </template>
    </wd-input>
  </wd-form-item>
</wd-form>

Attributes

ParameterDescriptionTypeDefault Value
v-modelInput box binding valuestring | number''
typeInput box type, optional values are text, number, digit, idcard, safe-password, nickname, telInputTypetext
placeholderPlaceholder textstringPlease enter...
placeholder-styleplaceholder style, currently supports color, font-size, font-weightstring-
placeholder-classplaceholder style classstring''
maxlengthMaximum input lengthnumberAlipay Mini Program has no default value, other platforms are -1
disabledWhether to disablebooleanfalse
readonlyWhether to read onlybooleanfalse
clearableWhether to display the clear buttonbooleanfalse
clear-trigger v1.3.7Clear button display timing, optional values are focus, alwaysInputClearTriggeralways
focus-when-clear v1.3.7Whether to auto focus after clicking the clear buttonbooleantrue
show-passwordWhether to display the password toggle buttonbooleanfalse
prefix-iconPrefix icon namestring-
suffix-iconSuffix icon namestring-
show-word-limitWhether to display character count, need to set maxlength at the same timebooleanfalse
errorWhether to display error statebooleanfalse
align-rightWhether the input content is right-alignedbooleanfalse
compactWhether to enable compact mode; when not explicitly set, it will be automatically enabled in wd-form-itemboolean-
focusWhether to get focusbooleanfalse
cursor-spacingDistance between cursor and keyboardnumber0
cursorCursor position when getting focusnumber-1
selection-startCursor start position, need to be used with selection-endnumber-1
selection-endCursor end position, need to be used with selection-startnumber-1
adjust-positionWhether to automatically push up the page when the keyboard pops upbooleantrue
hold-keyboardWhether to keep the keyboard from closing when clicking the page while focusedbooleanfalse
confirm-typeText on the bottom right button of the keyboard, optional values are done, go, next, search, sendInputConfirmTypedone
confirm-holdWhether to keep the keyboard from closing when clicking the bottom right button of the keyboardbooleanfalse
always-embedWhether to force input to be in the same layer state, only valid for WeChat Mini Program iOSbooleanfalse
ignore-composition-event v1.3.11Whether to ignore text composition system event processing; when false, composition related events will be triggered, and input will be triggered during compositionbooleantrue
inputmode v1.5.0Input mode hint, optional values are none, text, decimal, numeric, tel, search, email, urlInputModetext
enable-native v1.14.0Whether to enable native input box in Alipay Mini Program, set to false to avoid content shifting up after the keyboard pops upbooleantrue
custom-input-classInput box custom class namestring''
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

InputMode Optional Values

inputmode is an HTML specification extension capability added later. It can be used in uni-app's Web and App-Vue platforms in high-version WebViews that meet the conditions. For details, see inputmode.

ValueDescription
noneDo not pop up virtual keyboard
textStandard text input keyboard
decimalDecimal input keyboard
numericPure numeric input keyboard
telPhone input keyboard
searchSearch input optimized keyboard
emailEmail input optimized keyboard
urlURL input optimized keyboard

Events

Event NameDescriptionParameters
inputTriggered when inputting{ value, cursor, keyCode }
focusTriggered when focusing{ value, height }
blurTriggered when blurring{ value }
clearTriggered when clicking the clear button-
confirmTriggered when clicking the keyboard done button{ value }
keyboardheightchangeTriggered when keyboard height changes{ height, duration }
clickprefixiconTriggered when clicking the prefix icon-
clicksuffixiconTriggered when clicking the suffix icon-
clickTriggered when clicking the component root nodeevent: MouseEvent

Slots

NameDescription
prefixCustomize prefix content
suffixCustomize suffix content

External Style Classes

Class NameDescription
custom-classRoot node style class
custom-input-classInput box style class

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-input-padding$padding-loose $padding-loose输入框内边距
--wot-input-bg$filled-oppo输入框背景色
--wot-input-inner-height$n-20输入框内高度
--wot-input-inner-font-size$typography-body-size-main输入框内字号
--wot-input-inner-color$text-main输入框文字颜色
--wot-input-inner-placeholder-color$text-placeholder输入框占位符颜色
--wot-input-disabled-color$text-disabled输入框禁用颜色
--wot-input-icon-color$icon-secondary输入框图标颜色
--wot-input-icon-font-size$n-18输入框图标字号
--wot-input-icon-margin$spacing-tight输入框图标间距
--wot-input-count-margin$spacing-extra-loose输入框字数统计间距
--wot-input-count-color$text-auxiliary输入框字数统计颜色
--wot-input-count-font-size$typography-body-size-main输入框字数统计字号
--wot-input-count-line-height$typography-body-line--height-size-main输入框字数统计行高
--wot-input-error-color$danger-main输入框错误颜色

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.