Textarea Textarea
Enter multiline text with word counts, automatic height and validation.
Import
Use <hui-textarea> 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-textarea
ref="control"
v-model="value"
placeholder="请输入备注 / Enter notes"
clearable
show-word-limit
:maxlength="100"
:autosize="{ minRows: 2, maxRows: 4 }"
@update:model-value="event0"
@input="event1"
@change="event2"
@focus="event3"
@blur="event4"
@clear="event5"
@confirm="event6"
@keyboardheightchange="event7"
@linechange="event8"
/><text>值 / Value: {{ value }}</text
><hui-button @click="control?.focus()">聚焦 / Focus</hui-button
><hui-button @click="control?.clear()">清空 / Clear</hui-button>
<hui-textarea readonly default-value="只读内容 / Read only" /><hui-textarea
disabled
default-value="禁用内容 / Disabled"
/>
<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 = 'linechange' + ': ' + [describe(arg0)].join(', ')
}
</script>
The example grows from two to four rows and scrolls internally beyond four rows. autosize=true has no maximum; when disabled, rows determines the height.
Ordinary Vue Web computes automatic height locally and does not emit linechange. Native fixed and showConfirmBar options are platform-specific. Set fixed inside a fixed-position container such as Popup; a missing setting produces one development warning for the native textarea.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
rows | number | 3 | Initial textarea row count. |
autosize | boolean | TextareaAutosize | false | Grow with content. Object minRows overrides rows; content scrolls internally beyond maxRows. |
fixed | boolean | false | Use fixed positioning. |
showConfirmBar | boolean | false | Show the native keyboard confirmation bar. |
disableDefaultPadding | boolean | true | Disable native textarea default padding. |
modelValue | string | number | null | undefined | Controlled value; undefined means omitted. |
defaultValue | string | number | '' | Initial uncontrolled value; ignored in controlled mode. |
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. |
disabled | boolean | false | Disable interaction. |
readonly | boolean | undefined | Read-only presentation without value changes. |
size | ComponentSize | — | Component size; inherits configuration when omitted. |
border | boolean | false | Show a border or separator. |
autofocus | boolean | false | Request focus after mounting, subject to platform restrictions. |
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. |
linechange | (value: unknown) | Reports the corresponding interaction result. |
Slots
None.
Methods
| Method | Signature | Description |
|---|---|---|
focus | (): void | Request input focus. |
blur | (): void | Request input blur. |
clear | (): void | Clear using the component input flow. |
Types
TextareaProps、TextareaAutosize、TextareaExpose、TextareaEmits are available from @nscode/handy-uni.
export interface TextareaAutosize {
minRows?: number
maxRows?: number
}
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 |
| Native options | uni textarea | Verify fixed, autosize and keyboard | Verify keyboard dismissal and native stacking | Computes autosize; no linechange; fixed/showConfirmBar ignored |
Follow the smoke checklist. Device evidence is tracked separately; unit tests do not establish device acceptance.