Skip to content

Textarea

Used for entering multi-line text information, supporting clear, word count, auto-height adjustment, and compact layout.

Component Types

Basic Usage

Bind textarea content through v-model, set placeholder prompt through placeholder.

html
<wd-textarea v-model="value" placeholder="Please fill in the review" />
typescript
import { ref } from 'vue'

const value = ref('')

Component States

Read-only

Set textarea to read-only state through readonly.

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

Disabled

Disable textarea through disabled.

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

Component Variants

Clear Button and Word Limit

Enable clear button through clearable, display word count through maxlength and show-word-limit.

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

Show Clear Button on Focus

Control showing clear button only when focused and has value through clear-trigger="focus".

Note

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

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

Do Not Auto-focus After Clear

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

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

Auto Height

Make textarea height change with content through auto-height.

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

Component Styles

Compact Layout

After setting compact, default padding and background will be removed, suitable for use with containers like wd-form-item.

html
<wd-textarea v-model="value" compact placeholder="Please fill in the review" />

Special Styles

Using with Form

For current form scenarios, it is recommended to have wd-form and wd-form-item carry the title, required state, and validation prompts, while wd-textarea is only responsible for multi-line input capability.

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

  <wd-form-item title="Word Limit" prop="limit">
    <wd-textarea v-model="formData.limit" :maxlength="240" show-word-limit clearable compact placeholder="Please enter" />
  </wd-form-item>

  <wd-form-item title="Read-only" prop="readonly">
    <wd-textarea v-model="formData.readonly" readonly :maxlength="240" show-word-limit placeholder="Please enter" compact />
  </wd-form-item>
</wd-form>

Attributes

ParameterDescriptionTypeDefault Value
v-modelTextarea binding valuestring | number''
placeholderPlaceholder textstringPlease enter...
placeholder-styleplaceholder stylestring-
placeholder-classplaceholder style classstring''
disabledWhether to disablebooleanfalse
readonlyWhether read-onlybooleanfalse
maxlengthMaximum input length, set to -1 for unlimited lengthnumber-1
clearableWhether to show clear buttonbooleanfalse
show-word-limitWhether to show word count, requires maxlength to be setbooleanfalse
clear-trigger v1.3.7Clear button display timing, optional values are focus, alwaysInputClearTriggeralways
focus-when-clear v1.3.7Whether to auto-focus after clicking clear buttonbooleantrue
errorWhether to show error statebooleanfalse
focusWhether to get focusbooleanfalse
auto-focusWhether to auto-focus and bring up keyboardbooleanfalse
auto-heightWhether to auto-increase input box heightbooleanfalse
fixedWhether to enable fixed mode when in position: fixed areabooleanfalse
cursor-spacingDistance between cursor and keyboardnumber0
cursorCursor position when getting focusnumber-1
confirm-typeText on keyboard bottom-right button, optional values are done, go, next, search, sendConfirmType-
confirm-holdWhether to keep keyboard open when clicking keyboard bottom-right buttonbooleanfalse
show-confirm-barWhether to show toolbar with "Done" button above keyboardbooleantrue
selection-startCursor start position, needs to be used with selection-endnumber-1
selection-endCursor end position, needs to be used with selection-startnumber-1
adjust-positionWhether to automatically push up page when keyboard pops upbooleantrue
disable-default-paddingWhether to remove default padding on iOSbooleanfalse
hold-keyboardWhether to keep keyboard open when clicking page while focusedbooleanfalse
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 keyboard pops upbooleantrue
compactWhether to enable compact mode; when not explicitly set, it will be automatically enabled in wd-form-itemboolean-
custom-textarea-classTextarea custom class namestring''
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

InputMode Optional Values

inputmode is an HTML specification extension capability that can be used in uni-app's Web and App-Vue platforms in high-version WebViews that meet the conditions. See inputmode for details.

ValueDescription
noneDo not show 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, cursor }
clearTriggered when clicking clear button-
linechangeTriggered when line count changes{ height, heightRpx, lineCount }
confirmTriggered when clicking keyboard done button{ value }
keyboardheightchangeTriggered when keyboard height changes{ height, duration }

External Style Classes

Class NameDescription
custom-classRoot node style class
custom-textarea-classTextarea style class

主题定制

CSS 变量

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

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

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.