前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >微信小程序官方组件展示之表单组件textarea源码

微信小程序官方组件展示之表单组件textarea源码

作者头像
软件事业部
修改2022-09-26 10:56:33
1K0
修改2022-09-26 10:56:33
举报
文章被收录于专栏:软件事业部专栏

以下将展示微信小程序之表单组件textarea源码官方组件能力,组件样式仅供参考,开发者可根据自身需求定义组件样式,具体属性参数详见小程序开发文档。

功能描述:

多行输入框。该组件是原生组件,使用时请注意相关限制。。

属性说明:

WebView

属性

类型

默认值

必填

说明

最低版本

value

string

输入框的内容

1.0.0

placeholder

string

输入框为空时占位符

1.0.0

placeholder-style

string

指定 placeholder 的样式,目前仅支持 color ,font-size和font-weight

1.0.0

placeholder-class

string

textarea-placeholder

指定 placeholder 的样式类

1.0.0

disabled

boolean

FALSE

是否禁用

1.0.0

maxlength

number

140

最大输入长度,设置为 -1 的时候不限制最大长度

1.0.0

auto-focus

boolean

FALSE

自动聚焦,拉起键盘。

1.0.0

focus

boolean

FALSE

获取焦点

1.0.0

auto-height

boolean

FALSE

是否自动增高,设置 auto-height 时,style.height不生效

1.0.0

fixed

boolean

FALSE

如果 textarea 是在一个 `position:fixed` 的区域,需要显示指定属性 fixed 为 true

1.0.0

cursor-spacing

number

0

指定光标与键盘的距离。取`textarea`距离底部的距离和`cursor-spacing`指定的距离的最小值作为光标与键盘的距离

1.0.0

cursor

number

-1

指定 focus 时的光标位置

1.5.0

show-confirm-bar

boolean

TRUE

是否显示键盘上方带有”完成“按钮那一栏

1.6.0

selection-start

number

-1

光标起始位置,自动聚集时有效,需与`selection-end`搭配使用

1.9.0

selection-end

number

-1

光标结束位置,自动聚集时有效,需与`selection-start`搭配使用

1.9.0

adjust-position

boolean

TRUE

键盘弹起时,是否自动上推页面

1.9.90

hold-keyboard

boolean

FALSE

focus时,点击页面的时候不收起键盘

2.8.2

disable-default-padding

boolean

FALSE

是否去掉 iOS 下的默认内边距

2.10.0

confirm-type

string

return

设置键盘右下角按钮的文字

2.13.0

合法值

说明

send

右下角按钮为“发送”

search

右下角按钮为“搜索”

next

右下角按钮为“下一个”

go

右下角按钮为“前往”

done

右下角按钮为“完成”

return

右下角按钮为“换行”

confirm-hold

boolean

FALSE

点击键盘右下角按钮时是否保持键盘不收起

2.16.0

bindfocus

eventhandle

输入框聚焦时触发,event.detail = { value, height },height 为键盘高度,在基础库 1.9.90 起支持

1.0.0

bindblur

eventhandle

输入框失去焦点时触发,event.detail = {value, cursor}

1.0.0

bindlinechange

eventhandle

输入框行数变化时调用,event.detail = {height: 0, heightRpx: 0, lineCount: 0}

1.0.0

bindinput

eventhandle

当键盘输入时,触发 input 事件,event.detail = {value, cursor, keyCode},keyCode 为键值,目前工具还不支持返回 keyCode 参数。**bindinput 处理函数的返回值并不会反映到 textarea 上**

1.0.0

bindconfirm

eventhandle

点击完成时, 触发 confirm 事件,event.detail = {value: value}

1.0.0

bindkeyboardheightchange

eventhandle

键盘高度发生变化的时候触发此事件,event.detail = {height: height, duration: duration}

2.7.0

Skyline

属性

说明

placeholder-style

需传入对象,格式为 `{ fontSize: number, fontWeight: string, color: string }`

placeholder-class

暂未计划

fixed

不支持

Bug & Tip

1.tip: textarea 的 blur 事件会晚于页面上的 tap 事件,如果需要在 button 的点击事件获取 textarea,可以使用 form 的 bindsubmit。

2.tip: 不建议在多行文本上对用户的输入进行修改,所以 textarea 的 bindinput 处理函数并不会将返回值反映到 textarea 上。

3.tip : 键盘高度发生变化,keyboardheightchange事件可能会多次触发,开发者对于相同的 height 值应该忽略掉

4.bug: 微信版本 6.3.30,textarea 在列表渲染时,新增加的 textarea 在自动聚焦时的位置计算错误。

示例代码

JAVASCRIPT:

代码语言:javascript
复制
//textarea.js
Page({
  data: {
    height: 20,
    focus: false
  },
  bindButtonTap: function() {
    this.setData({
      focus: true
    })
  },
  bindTextAreaBlur: function(e) {
    console.log(e.detail.value)
  },
  bindFormSubmit: function(e) {
    console.log(e.detail.value.textarea)
  }
})

WXML:

代码语言:javascript
复制
<view class="section">
  <textarea bindblur="bindTextAreaBlur" auto-height placeholder="自动变高" />
</view>
<view class="section">
  <textarea placeholder="placeholder颜色是红色的" placeholder-style="color:red;"  />
</view>
<view class="section">
  <textarea placeholder="这是一个可以自动聚焦的textarea" auto-focus />
</view>
<view class="section">
  <textarea placeholder="这个只有在按钮点击的时候才聚焦" focus="{{focus}}" />
  <view class="btn-area">
    <button bindtap="bindButtonTap">使得输入框获取焦点</button>
  </view>
</view>
<view class="section">
  <form bindsubmit="bindFormSubmit">
    <textarea placeholder="form 中的 textarea" name="textarea"/>
    <button form-type="submit"> 提交 </button>
  </form>
</view>

版权声明: 本站所有内容均由互联网收集整理、上传,如涉及版权问题,请联系我们第一时间处理。

原文链接地址:https://developers.weixin.qq.com/miniprogram/dev/component/textarea.html

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云开发 CloudBase
云开发(Tencent CloudBase,TCB)是腾讯云提供的云原生一体化开发环境和工具平台,为200万+企业和开发者提供高可用、自动弹性扩缩的后端云服务,可用于云端一体化开发多种端应用(小程序、公众号、Web 应用等),避免了应用开发过程中繁琐的服务器搭建及运维,开发者可以专注于业务逻辑的实现,开发门槛更低,效率更高。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档