Skip to content

Textarea 文本域

介绍

文本框内输入或编辑文字,支持限制输入数量。

基础用法

html
<template>
  <nut-textarea v-model="value"></nut-textarea>
</template>
ts
const value = ref("");

显示字数统计

html
<template>
  <nut-textarea v-model="value" max-length="20" limit-show></nut-textarea>
</template>

自动高度

html
<template>
  <nut-textarea v-model="value" autosize></nut-textarea>
</template>

只读、禁用

html
<template>
  <nut-textarea model-value="只读状态" readonly></nut-textarea>
  <nut-textarea model-value="禁用状态" disabled></nut-textarea>
</template>

API

Props

参数说明类型可选值默认值
v-model输入值string--
textarea-style 1.7.3文本域自定义样式StyleValue--
textarea-class 1.7.3文本域自定义类名ClassType--
placeholder设置占位提示文字string-请输入内容
placeholder-style 1.6.9指定 placeholder 的样式string--
placeholder-class 1.6.9指定 placeholder 的样式类string-textarea-placeholder
max-length限制最长输入字符string / number--
rows H5行数,优先级高于 autosize 属性string / number--
limit-show是否展示输入字符,配合 max-length 使用boolean-false
autosize是否自适应内容高度,也可传入对象,如 { minHeight: 100, maxHeight: 200 }(单位:px)boolean / object-false
text-align文本位置stringleft / center / right-
readonly只读属性boolean-false
disabled禁用属性boolean-false
autofocus自动获取焦点boolean-false
cursor-spacing指定光标与键盘的距离number-0
cursor指定focus时的光标位置number--1
show-confirm-bar是否显示键盘上方带有“完成”按钮那一栏boolean-true
selection-start光标起始位置,自动聚集时有效,需与 selection-end 搭配使用number--1
selection-end光标结束位置,自动聚集时有效,需与 selection-start 搭配使用number--1
adjust-position键盘弹起时,是否自动上推页面boolean-true
hold-keyboardfocus 时,点击页面的时候不收起键盘boolean-false
disable-default-padding是否去掉 iOS 下的默认内边距boolean-false
confirm-type设置键盘右下角按钮的文字stringsend / search / next / go / done / returnreturn
confirm-hold点击键盘右下角按钮时是否保持键盘不收起boolean-false
adjust-keyboard-to键盘对齐位置stringcursor / bottomcursor

Events

事件名说明类型
change输入框值改变时触发(value: string, event: Event) => void
focus聚焦时触发(event: TextareaOnFocusEvent) => void
blur失焦时触发(event: TextareaOnBlurEvent) => void
confirm点击完成按钮时触发(event: TextareaOnConfirmEvent) => void
input键盘输入时触发(value: string, event: TextareaOnInputEvent) => void

主题定制

样式变量

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

名称默认值
--nut-textarea-fontvar(--nut-font-size-2)
--nut-textarea-limit-colorvar(--nut-text-color)
--nut-textarea-text-colorvar(--nut-title-color)
--nut-textarea-disabled-colorvar(--nut-disable-color)

MIT Licensed