Skip to content

H5预览

APP下载

Textarea 文本域

cl-textarea 组件基于 uni-app 的 textarea 组件,提供了丰富的多行文本输入功能和样式定制能力。

参数

参数说明类型可选值默认值
pt样式穿透配置PassThrough
modelValue双向绑定的输入值string""
inputmode输入键盘类型string"none" | "text" | "decimal" | "numeric" | "tel" | "search" | "email" | "url""text"
autofocus是否自动获取焦点booleanfalse
placeholder输入框为空时显示的占位符文本string"请输入"
placeholderClass占位符文本的自定义样式类名string""
border是否显示输入框边框booleanfalse
maxlength最大输入字符数限制number140
disabled是否禁用输入框booleanfalse
readonly是否设置为只读状态booleanfalse
fixed如果 textarea 是在 position:fixed 的区域,需要显示指定属性 fixed 为 truebooleanfalse
height文本域高度number | string120
autoHeight是否自动调整高度booleanfalse
showWordLimit是否显示字数统计booleantrue
clearable是否显示清空按钮booleanfalse
cursorColor光标颜色string
cursorSpacing指定光标与键盘的距离(单位:px)number5
confirmHold点击键盘确认按钮时是否保持键盘不收起booleanfalse
confirmType设置键盘右下角按钮的文字string"done" | "go" | "next" | "search" | "send"done
showConfirmBar是否显示键盘上方带有"完成"按钮那一栏booleantrue
holdKeyboard焦点时,点击页面的时候不收起键盘booleanfalse
selectionStart光标起始位置,自动聚集时有效,需与 selection-end 搭配使用number-1
selectionEnd光标结束位置,自动聚集时有效,需与 selection-start 搭配使用number-1
adjustPosition键盘弹起时,是否自动上推页面booleantrue
adjustKeyboardTo键盘对齐位置string"cursor" | "bottom""cursor"

事件

事件说明
input输入内容时触发
change输入内容发生变化时触发
focus输入框获得焦点时触发
blur输入框失去焦点时触发
confirm点击键盘确认按钮时触发
clear点击清空按钮时触发
linechange输入框行数变化时触发
keyboardheightchange键盘高度发生变化的时候触发

PassThrough

样式穿透配置,用于自定义组件内部元素的样式。

参数说明类型
className组件根元素样式string
inner内部输入框配置PassThroughProps

示例

基本用法

最简单的文本域用法:

html
<cl-textarea></cl-textarea>

带边框

添加边框样式:

html
<cl-textarea border></cl-textarea>

自动调整高度

根据内容自动调整文本域高度:

html
<cl-textarea auto-height></cl-textarea>

显示字数统计

配置 show-word-limit 属性显示字数统计:

html
<cl-textarea show-word-limit></cl-textarea>

自定义样式

通过 pt 属性自定义组件样式:

vue
<cl-textarea
  :pt="{
    className: '!bg-sky-100 !border-sky-700',
    inner: {
      className: '!text-sky-700',
    },
  }"
></cl-textarea>