textarea

Multi-row entry box

Property

TypeDefaultDescription
nameStringComponent name, used for form submission to get data.
valueStringInitial contents.
placeholderStringPlaceholder.
placeholder-styleStringSpecify placeholder style.
placeholder-classStringSpecify placeholder style class.
disabledBooleanfalseDisable or not.
maxlengthNumber140Maximum length, no length limit when setting is -1.
focusBooleanfalseGet focus.
auto-heightBooleanfalseUse auto height or not.
show-countBooleantrueRender wordcount statistics or not.
controlledBooleanfalseIs controlled component or not When it is true, the value content is fulled controlled by setData.
onInputEventHandleTrigger on keyboard entry, event.detail = {value: value}, can return directly a string to replace the contents in the entry box.
onFocusEventHandleTrigger on entry box getting focus, event.detail = {value: value}.
onBlurEventHandleRigger on entry box losing focus, event.detail = {value: value}.
onConfirmEventHandleRrigger on clicking completion, event.detail = {value: value}.

Screenshot

image

Sample Code

copy
<view class="section">
  <textarea onBlur="bindTextAreaBlur" auto-height placeholder="Auto height" />
</view>
<view class="section">
  <textarea placeholder="Get focus only when this button is clicked" focus="{{focus}}" />
  <view class="btn-area">
    <button onTap="bindButtonTap">Have entry box get focus</button>
  </view>
</view>
<view class="section">
  <form onSubmit="bindFormSubmit">
    <textarea placeholder="textarea in the form" name="textarea"/>
    <button form-type="submit"> Submit </button>
  </form>
</view>
copy
Page({
  data: {
    focus: false,
    inputValue: ''
  },
  bindButtonTap() {
    this.setData({
      focus: true
    })
  },
  bindTextAreaBlur: function(e) {
    console.log(e.detail.value)
  },
  bindFormSubmit: function(e) {
    console.log(e.detail.value.textarea)
  }
})