Skip to content

'# Textarea 0.2.0

Used for inputting multi-line text information.

Basic Usage

You can use v-model for two-way binding of the input value and set placeholder text through placeholder.

html
<wd-textarea v-model="value" placeholder="Please enter your comment" />
typescript
const value = ref<string>('')

Disabled

Enable the disabled state by setting the disabled property.

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

Read-only

Enable the read-only state by setting the readonly property.

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

Clear Button

Enable the clear button by setting the clearable property, and implement character limit by setting show-word-limit and maxlength.

html
<wd-textarea v-model="value" :maxlength="120" clearable show-word-limit />

Show Clear Button on Focus

Set the clear-trigger property to control whether to show the clear button only when focused.

Note

Alipay Mini Program currently does not support the clear-trigger property, and in some cases, the clear button cannot be clicked. Please refer to this issue (Hoping it can be resolved soon, so I directly raised an issue in Ant's component library).

html
<wd-textarea clear-trigger="focus" v-model="value14" :maxlength="120" clearable show-word-limit />

Don't Auto Focus After Clearing

Set the focus-when-clear property to control whether to automatically focus after clicking the clear button.

html
<wd-textarea v-model="value" :focus-when-clear="false" :maxlength="120" clearable show-word-limit />

Auto Height

Enable auto height adjustment by setting the auto-height property.

html
<wd-textarea v-model="value" auto-height />

Prefix Icon

Set a prefix icon using prefix-icon, where the icon should be a class name from the icon section. If you need a custom icon that's not available, use the prefix slot instead.

html
<wd-textarea v-model="value" prefix-icon="dong"></wd-textarea>

Setting Label Title

Set a label title, which can be used with cell-group to create a cell display type. You can set the title width through label-width, which defaults to '33%'.

html
<wd-cell-group border>
  <wd-textarea label="Basic Usage" clearable v-model="value" placeholder="Please enter..." />
</wd-cell-group>

Required Style

When a label is set, you can set the required property to display the required style.

html
<wd-textarea v-model="value" placeholder="Please enter..." label="Required" required></wd-textarea>

Input Size

Modify the input size by setting size. When size is set to 'large', the font size is 16px.

html
<wd-textarea label="Basic Usage" size="large" v-model="value" placeholder="Please enter..." />

Error State

Set the error property to display the input value in red.

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

Vertical Center

When a label title is set, it defaults to top alignment. Set the center property to vertically center the title and input box.

html
<wd-textarea label="Basic Usage" v-model="value" center />

Attributes

ParameterDescriptionTypeOptionsDefaultVersion
v-modelBinding valuestring / number---
placeholderPlaceholder textstring-Please enter...-
placeholderStyleNative attribute, specify placeholder stylestring---
placeholderClassNative attribute, specify placeholder style classstring---
disabledNative attribute, disabled stateboolean-false-
maxlengthNative attribute, maximum input length, set to -1 for no limitnumber---
auto-focusNative attribute, auto focus, brings up keyboardboolean-false-
focusNative attribute, get focusboolean-false-
auto-heightNative attribute, auto increase height (style.height doesn't work when set)boolean-false-
fixedNeed to set to true in position:fixed areasboolean-false-
cursorSpacingNative attribute, specify distance between cursor and keyboard (takes minimum of textarea bottom distance and this value)number-0-
cursorNative attribute, specify cursor position when focusednumber--1-
confirm-typeSet text of keyboard's bottom-right buttonstringdone/go/next/search/send--
confirm-holdWhether to keep keyboard open after clicking bottom-right buttonboolean-false-
show-confirm-barWhether to show "Done" bar above keyboardboolean-true-
selection-startNative attribute, cursor start position (must be used with selection-end)number--1-
selection-endNative attribute, cursor end position (must be used with selection-start)number--1-
adjust-positionNative attribute, whether to automatically push page up when keyboard risesboolean-true-
disable-default-paddingNative attribute, whether to remove iOS default paddingboolean-false-
hold-keyboardNative attribute, whether to keep keyboard open when clicking page while focusedboolean-false-
show-passwordDisplay as password fieldboolean-false-
clearableShow clear buttonboolean-false-
readonlyRead-onlyboolean-false-
prefix-iconPrefix icon (use icon component class name)string---
show-word-limitShow character limit (requires maxlength)boolean-false-
labelSet left titlestring---
label-widthSet left title widthstring-33%-
sizeSet input sizestring---
errorSet input error state (red indicator)boolean-false-
centerVertically center title and input box when label is set (defaults to top alignment)boolean-false-
no-borderWhether to hide underline in non-cell typeboolean-false-
requiredRequired style in cell typeboolean-false-
propForm field model name (required for form validation)string---
rulesForm validation rulesFormItemRule[]-[]-
clearTriggerWhen to show clear icon: always (show when input is not empty) / focus (show when focused and not empty)InputClearTriggerfocus/alwaysalways1.3.7
focusWhenClearWhether to focus input box when clicking clear buttonboolean-true1.3.7
ignoreCompositionEventWhether to ignore text composition system events (when false, triggers composition events and input events during composition)boolean-true1.3.11
inputmodeInput data type hintInputMode-text1.5.0

InputMode Options

Added in uni-app 3.6.16+. inputmode is a later addition to the HTML specification. Various mini programs do not yet support this property.

This property can be used in web and app-vue platforms of uni-app in compatible high-version webviews, see inputmode.

ValueDescription
noneNo virtual keyboard. Useful when the application or site needs to implement its own keyboard input control.
textUses the standard text input keyboard for the user's locale.
decimalNumeric keyboard with decimal separator (usually "." or ","), device may or may not show minus key.
numericNumeric keyboard, just needs numbers 0 to 9, device may or may not show minus key.
telTelephone input keyboard, includes numbers 0 to 9, asterisk (*), and pound (#) keys. Phone number input typically should use .
searchVirtual keyboard optimized for search input, for example, return key might be labeled "search", and may have other optimizations.
emailVirtual keyboard optimized for email address input, typically includes "@" symbol and other optimizations. Email address input should use .
urlVirtual keyboard optimized for URL input, for example, "/" key might be more prominent, history access, etc. URL input typically should use .

FormItemRule Data Structure

KeyDescriptionType
requiredWhether it's a required fieldboolean
messageError prompt textstring
validatorValidate through function, can return a Promise for asynchronous validation(value, rule) => boolean | Promise
patternValidate through regular expression, validation fails if regex doesn't matchRegExp

Events

Event NameDescriptionParametersVersion
inputListen to input box input event{value, cursor, keyCode}-
focusListen to input box focus event{ value, height }, height is keyboard height-
blurListen to input box blur event{ value }-
clearListen to input box clear button event--
linechangeListen to input box line number change{ height: 0, heightRpx: 0, lineCount: 0 }-
confirmTriggered when clicking done, triggers confirm event{ value }-

Source Code

Documentation
Component

Released under the MIT License.

Ask me