Input Input
Enter single-line text with filtering, clearing, icons and form validation.
Import
Use <hui-input> with uni-app easycom. Import public types from @nscode/handy-uni. For ordinary Vue 3, install the preview plugin from @nscode/handy-uni/web and register its components.
Examples
Interact with the controls to see values and event results on the page.
<template>
<view>
<hui-input
ref="control"
v-model="value"
placeholder="请输入 / Enter text"
clearable
show-word-limit
:maxlength="30"
prefix-icon="search"
suffix-icon="check"
@update:model-value="event0"
@input="event1"
@change="event2"
@focus="event3"
@blur="event4"
@clear="event5"
@confirm="event6"
@keyboardheightchange="event7"
@click-prefix-icon="event8"
@click-suffix-icon="event9"
/><text>值 / Value: {{ value }}</text
><hui-button @click="control?.focus()">聚焦 / Focus</hui-button
><hui-button @click="control?.clear()">清空 / Clear</hui-button>
<hui-input type="password" show-password placeholder="密码 / Password" /><hui-input
disabled
default-value="Disabled"
/><hui-input readonly default-value="Read only" /><hui-input
allow-input="int"
type="number"
placeholder="整数 / Integer"
/>
<hui-button @click="() => control?.focus()">focus()</hui-button>
<hui-button @click="() => control?.blur()">blur()</hui-button>
<hui-button @click="() => control?.clear()">clear()</hui-button>
<text>{{ lastEvent }}</text>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('No event yet')
const describe = (value: unknown) => {
try {
return JSON.stringify(value) ?? String(value)
} catch {
return String(value)
}
}
const control = ref()
const value = ref<string | number>('')
const event0 = (arg0: unknown) => {
lastEvent.value = 'update:modelValue' + ': ' + [describe(arg0)].join(', ')
}
const event1 = (arg0: unknown) => {
lastEvent.value = 'input' + ': ' + [describe(arg0)].join(', ')
}
const event2 = (arg0: unknown) => {
lastEvent.value = 'change' + ': ' + [describe(arg0)].join(', ')
}
const event3 = (arg0: unknown) => {
lastEvent.value = 'focus' + ': ' + [describe(arg0)].join(', ')
}
const event4 = (arg0: unknown) => {
lastEvent.value = 'blur' + ': ' + [describe(arg0)].join(', ')
}
const event5 = () => {
lastEvent.value = 'clear'
}
const event6 = (arg0: unknown) => {
lastEvent.value = 'confirm' + ': ' + [describe(arg0)].join(', ')
}
const event7 = (arg0: unknown) => {
lastEvent.value = 'keyboardheightchange' + ': ' + [describe(arg0)].join(', ')
}
const event8 = (arg0: unknown) => {
lastEvent.value = 'click-prefix-icon' + ': ' + [describe(arg0)].join(', ')
}
const event9 = (arg0: unknown) => {
lastEvent.value = 'click-suffix-icon' + ': ' + [describe(arg0)].join(', ')
}
</script>
Composition text is filtered after composition ends. Clearing emits input before change. Ordinary Vue Web does not emit keyboardheightchange and ignores adjustPosition/cursorSpacing.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue | string | number | null | undefined | Controlled value; undefined means omitted. |
defaultValue | string | number | '' | Initial uncontrolled value; ignored in controlled mode. |
type | InputType | 'text' | Semantic type or input mode; see the type definition. |
allowInput | InputAllowInput | — | Input filter preset, regular expression or function; applied after composition. |
placeholder | string | — | Placeholder when no value is selected or entered. |
maxlength | number | — | Maximum input length. |
showWordLimit | boolean | false | Display the current character count and limit. |
clearable | boolean | false | Show the clear action. |
clearTrigger | "focus" | "always" | 'focus' | Show the clear action always or only while focused. |
showPassword | boolean | false | Show the password-visibility toggle. |
disabled | boolean | false | Disable interaction. |
readonly | boolean | undefined | Read-only presentation without value changes. |
size | ComponentSize | — | Component size; inherits configuration when omitted. |
align | "left" | "right" | 'left' | Text alignment. |
border | boolean | false | Show a border or separator. |
prefixIcon | string | — | Leading input icon. |
suffixIcon | string | — | Trailing input icon. |
autofocus | boolean | false | Request focus after mounting, subject to platform restrictions. |
confirmType | "done" | "go" | "next" | "search" | "send" | 'done' | Keyboard confirmation-key hint. |
confirmHold | boolean | false | Keep the keyboard after confirmation where the native control supports it. |
adjustPosition | boolean | true | Allow the native control to adjust page position for the keyboard. |
cursorSpacing | number | 0 | Cursor-to-keyboard distance in px; native capability only. |
validateEvent | boolean | true | Trigger form-item validation on changes or blur. |
name | string | — | Item identifier or registered icon name. |
ariaLabel | string | — | Accessible name. |
Root attributes: common props. A Boolean default of undefined supports inheritance; explicit false overrides it. Other Boolean props default to false unless listed otherwise.
Events
| Event | Parameters | Description |
|---|---|---|
update:modelValue | (value: string | number | null) | Request a controlled value update. |
input | (value: string | number | null) | Emitted with the normalized input value. |
change | (value: string | number | null) | Emitted after the value changes. |
focus | (value: unknown) | Input gained focus. |
blur | (value: unknown) | Input lost focus. |
clear | () | Emitted after clearing. |
confirm | (value: string | number | null) | Confirmation action. |
keyboardheightchange | (value: unknown) | Reports the corresponding interaction result. |
click-prefix-icon | (value: unknown) | Reports the corresponding interaction result. |
click-suffix-icon | (value: unknown) | Reports the corresponding interaction result. |
Slots
| Slot | Parameters | Description |
|---|---|---|
prefix | — | Custom prefix region; replaces its fallback content. |
suffix | — | Custom suffix region; replaces its fallback content. |
append | — | Custom append region; replaces its fallback content. |
Methods
| Method | Signature | Description |
|---|---|---|
focus | (): void | Request input focus. |
blur | (): void | Request input blur. |
clear | (): void | Clear using the component input flow. |
Types
InputProps、InputType、InputAllowInput、InputExpose、InputEmits are available from @nscode/handy-uni.
export type InputType = 'text' | 'number' | 'digit' | 'idcard' | 'tel' | 'password' | 'nickname'
export type InputAllowInput = SharedInputAllowInput
Platform notes
| Behavior | uni-app H5 | WeChat Mini Program | App-vue | Ordinary Vue 3 Web (preview) |
|---|---|---|---|---|
| Basic interaction | Supported; device checks pending | Supported; device checks pending | Supported; device checks pending | Supported by the web platform adapter |
| Input and keyboard | Normalized through uni input | Verify focus, confirm and keyboard height on device | Verify the zero-height callback when dismissing the keyboard | Composition supported; no keyboardheightchange; adjustPosition/cursorSpacing ignored |
Follow the smoke checklist. Device evidence is tracked separately; unit tests do not establish device acceptance.