multi-line input
WdTextarea
Applicable Scenarios
For multi-line content input.
Basic Capabilities Description
Bind the 'text' type field. After the form container is bound to the data model, text fields in the model (with the format selected as multi-line text) are automatically rendered as a multi-line input component, enabling multi-line data entry. Configurable properties include input value, placeholder text, component size, and whether to horizontally fill (component size and whether to horizontally fill are effective on PC but not on mobile).
Supports personalized configuration of titles, including title content, alignment, whether to wrap (when enabled, wraps to the next line if title text exceeds one line; when disabled, truncates with ellipsis if title text exceeds one line), title position, width, and title tooltip.
- Supports personalized configuration of the input box, including the hint below the input box, whether to display character count, whether to automatically get focus, whether to display an underline on mobile / whether to display the input box on PC.
Note:
- Unlike the single-line input, the multi-line input component lacks configurations for prefix/suffix text and prefix/suffix icons.
- Size configuration applies only to the PC end.
- If the component is within a form container, its size, title alignment, position, line wrapping, and width will inherit the form container's property configuration by default.
- The multi-line input component displays the character count of the input by default.
- The multi-line input component has a default height of two lines. At runtime, the height automatically increases based on the input content. When the input exceeds ten lines, content can be viewed via scrollbars.
To learn more about usage scenarios for form components, refer to the Form Common Scenarios Practice Guide.
Example
Interactive Preview
Component Decoration
Component Size
Component Alignment
Component Input State
Component Style API Example
#wd-page-root .wd-form-item .wd-textarea-textarea {
border-color: cyan;
color: cyan;
background-color: black;
border-width: 2px;
border-radius: 6px;
--wd-color-text-placeholder: red;
}
Properties
组件接收的外部传入的属性
属性名 | 属性标识 | 类型 | 说明 |
---|
显示标题 | labelVisible | boolean | 默认值:true |
标题对齐 | labelAlign | string | 表单场景下默认会跟随表单容器的标题对齐配置 |
标题换行 | labelWrap | boolean | 如果标题内容过长关闭时只显示一行、溢出省略;开启时换行展示。表单场景下默认会跟随表单容器的标题换行配置 |
标题位置 | layout | string | 设置标题在表单组件的展示位置,表单场景下默认会跟随表单容器的标题的位置配置 |
标题宽度 | labelWidth | string | 表单场景下默认会跟随表单容器的标题宽度配置 |
标题提示 | labelTips | string | 配置标题的工具提示内容 |
光标距键盘距离 | cursorSpacing | number | 指定光标与键盘的距离。取textarea距离底部的距离和cursor-spacing指定的距离的最小值作为光标与键盘的距离;仅小程序端生效。 |
下方提示 | extra | string | 配置后提示内容常显在输入框下方 |
显示字数 | counterVisible | boolean | 默认值:true |
自动获取焦点 | focus | boolean | 开启后页面加载后光标自动定位到该输入框 |
是否自动增高 | autoHeight | boolean | 是否自动增高,设置style.height时,auto-height不生效。 默认值:true |
移动端显示下划线 | borderedH5 | boolean | 关闭后移动端不显示底部下划线 默认值:true |
PC端显示输入边框 | borderedPc | boolean | 关闭后PC端不显示输入边框 默认值:true |
最大长度 | maxLength | number | 默认值:140 |
校验规则 | rules | array | 默认值:[] |
状态 | status | string | 示例:"edit" |
必填 | required | boolean | |
必填标识 | requiredFlag | boolean | 启用后,组件若要求必填,则会显示必填星号标记 默认值:true |
必填校验提示 | requiredMsg | string | 示例:"该项为必填项" |
绑定字段 | name | string | 表单字段的Key值,用于提交数据时,匹配数据模型字段标识。表单内需保证唯一。 示例:"formTextarea" |
标题内容 | label | string | 示例:"标题" |
输入值 | value | string | 示例:"" |
占位文字 | placeholder | string | 示例:"请输入" |
PC端组件尺寸 | size | string | 尺寸配置仅对PC端生效,表单场景下默认会跟随表单容器的组件尺寸配置 |
Events
组件暴露的事件,可以监听组件的事件来触发一些外部的动作
事件名 | 事件code | 事件出参 event.detail | 适用情况 | 说明 |
---|
值改变 | change | object
| 兼容三端 | 用户修改组件值时触发 |
聚焦 | focus | object
| 兼容三端 | - |
失焦 | blur | object
| 兼容三端 | - |
确认 | confirm | object
| 兼容三端 | web端键盘输入enter时触发 |
Property API
通过属性 API,可以获取组件内部的状态和属性值,可以通过$w.componentId.propertyName
来访问组件内部的值,如 $w.input1.value
,详请请参考 属性 API
只读属性名 | 属性标识 | 类型 | 说明 |
---|
绑定字段 | name | string | 表单字段的Key值,用于提交数据时,匹配数据模型字段标识。表单内需保证唯一。 |
标题内容 | label | string | |
输入值 | value | string | |
必填 | required | boolean | |
是否展示 | visible | boolean | 组件是否展示 |
是否禁用 | disabled | boolean | 组件是否禁用 |
是否只读 | readOnly | boolean | 组件是否只读 |
Method API
通过方法 API,可以通过程序触发组件内部的方法,比如提交表单,显示弹窗等, 可以通过$w.componentId.methodName
来调用组件方法,如 $w.form1.submit()
方法名 | 方法标识 | 参数 | 方法说明 |
---|
设置值 | setValue | string 值 | 通过 $w.id1.setValue("weda") 设置组件值 |
设置显隐 | setVisible | boolean 显示 | 通过 $w.id1.setVisible(false) 设置组件为隐藏 |
设置禁用 | setDisabled | boolean 禁用 | 通过 $w.id1.setDisabled(true) 设置组件为禁用 |
清空值 | clearValue | 通过 $w.id1.clearValue() 清空组件值 | |
设置只读 | setReadOnly | boolean 只读 | 通过 $w.id1.setReadOnly(true) 设置组件为只读 |
触发校验 | handleValidate | 通过 $w.id1.handleValidate() 校验组件值 | |
清除校验 | clearValidate | 通过 $w.id1.clearValidate() 清除组件校验 |
Style API
通过样式 API,可以覆盖组件中内部元素的样式来实现自定义,例如在低代码编辑器中中通过 #wd-page-root .wd-btn
即可为所有的按钮组件编写样式,通过 :scope
可以控制单个组件样式, 详细说明请参考样式 API
名称 | 类名 | 说明和示例 |
---|
根元素 | .wd-textarea-root | 组件最外层元素
|
H5 端根元素 | .wd-h5-textarea-root | 可设定 H5 端的根元素样式
|
PC 端根元素 | .wd-pc-textarea-root | 可设定 PC 端的根元素样式
|
小程序端根元素 | .wd-mp-textarea-root | 可设定小程序端的根元素样式
|
组件标题样式 | .wd-textarea-root .wd-form-item-wrap__label | 组件标题元素
|
表单控件根节点样式 | .wd-textarea-root .wd-form-item-wrap__control | 设置表单控件根元素样式
|
编辑态-输入框样式 | .wd-textarea-root .wd-form-input-wrap | 组件边框、边距样式、背景色、字体大小、字体颜色等
|
编辑态-输入框样式(获取焦点) | .wd-textarea-root .wd-form-input-wrap.is-focused | 编辑态-输入框样式(获取焦点)
|
编辑态-占位文字样式 | .wd-textarea-root textarea::placeholder, .wd-textarea-root .weui-input__placeholder | 设置占位文字样式
|
编辑态-校验信息 | .wd-textarea-root .wd-g-text-error | 设置组件校验信息样式
|
提示文字 | .wd-textarea-root .wd-form-item__help-text | 设置组件提示文字样式
|
禁用态-输入框样式 | .wd-textarea-root .wd-form-input-wrap.is-disabled | 组件禁用样式
|
只读态-表单值样式 | .wd-textarea-root .wd-form-item__readonly-value | 设置组件只读状态
|
多行输入框内容输入区 | .wd-textarea__content | 多行输入框内容输入区
|
字数 | .wd-textarea-textarea__count-text | 多行输入框字数
|
字数 | .wd-textarea__count-text | 多行输入框字数
|
Version Changes
- Property changes
- Style changes
- widget api changes
Frequently Asked Questions
Why does the "cursor-to-keyboard distance" variable binding fail to take effect on ios devices after modification?
It's a Bug in the Mini Program itself; this property only takes effect on the initially passed value.
Why does setting a fixed height after disabling auto-height fail to take effect on ios devices?
ios Mini Program compatibility issue: After disabling the auto-height property, a fixed height must be set for the native textarea; otherwise, the default height expands to fill the entire page.
By default, this scenario sets height: 3rem
.
If you need to set a custom height for the textarea, you can specify it using the following style api.
:scope.wd-mp-textarea-root .wd-form-input-wrap textarea.wd-textarea__ios{
height: 300px
}