Item | Description |
|---|---|
Applicable devices | Mobile phones, tablets, Vision products, and telematics devices |
Applicable regions | Global |
In addition to general attributes and text, the attributes listed in the following table are supported.
Attribute | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
placeholder | string | - | No | Short hint that describes the expected value of the text area. |
maxlength | number | - | No | Maximum number of characters that can be entered in the text area. The empty value indicates no limit. |
The active pseudo-class is supported. In addition to common styles, the styles listed in the following table are supported.
Style | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
color | color | rgba(0,0,0,0.87) | No | Font color. |
font-size | number | 37.5px | No | Font size. |
font-weight (1030+) | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | normal | bold | bolder | normal | No | - |
placeholder-color | color | rgba(0,0,0,0.38) | No | Color of the short hint that describes the expected value of the text area. |
font-family (1030+) | string | - | No | Font of strings in the element. Default fonts normal, sans-serif, serif, and monospace are supported, which are valid only for English strings. To customize fonts, please refer to font-face Style. |
In addition to common events, the events listed in the following table are supported.
Event | Parameter | Description |
|---|---|---|
change | {text:newText} | The input changes. |
selectionchange (1030+) | - | The select() or setSelectionRange() method is called in the textarea element to change the selected string. |
linechange (1060+) | {height: number, lineCount:number} | The number of lines in the text box changes. The height parameter indicates the text box height, and the lineCount parameter indicates the number of lines in the text box. |
Method | Parameter | Description |
|---|---|---|
focus | {focus:true|false}. If the focus parameter is not passed, the default value true is used. | Sets focus on or remove focus from the element. It can trigger the focus pseudo-class, and pop up or fold up the input method. |
select | - | Selects all texts in a text box. |
setSelectionRange | {start:number,end:number} | Sets the area selected in a text box. |
getSelectionRange | {callback:function(start: number, end : number)} | Obtains the area selected in a text box. |
<template>
<div class="container">
<div class="page-title-wrap">
<text class="page-title">{{componentName}}</text>
</div>
<div class="item-container">
<div class="item-content">
<textarea id="textarea" maxlength="5" placeholder="Please enter content" class="textarea" @selectionchange="selectionchange"></textarea>
<text class="txt">Wrap text when there is too much text, scroll display when setting high</text>
</div>
<input class="select-button" value="select all" type="button" onclick="select"></input>
<input class="select-button" value="Set the selected area" type="button" onclick="setSelectionRange"></input>
<input class="select-button" value="Get the first and last position of the selected area" type="button" onclick="getSelectionRange"></input>
<div class="item-content">
<textarea class="textarea textarea-fontfamily"></textarea>
<text class="txt">this textarea font-family is serif</text>
</div>
</div>
</div>
</template>
<style>
.container {
flex: 1;
flex-direction: column;
}
.page-title-wrap {
padding-top: 50px;
padding-bottom: 80px;
justify-content: center;
}
.page-title {
padding-top: 30px;
padding-bottom: 30px;
padding-left: 40px;
padding-right: 40px;
border-color: #bbbbbb;
color: #bbbbbb;
border-bottom-width: 2px;
}
.item-container {
margin-bottom: 50px;
margin-right: 60px;
margin-left: 60px;
flex-direction: column;
}
.textarea {
border-color: #bbbbbb;
border-width: 1px;
padding: 15px;
height: 150px;
font-size: 30px;
color: #FF6347;
placeholder-color: #8A2BE2;
}
.item-content {
flex-direction: column;
background-color: #ffffff;
padding: 30px;
margin-bottom: 100px;
justify-content: center;
}
.select-button {
padding: 15px;
font-size: 30px;
color: #000000;
}
.textarea-fontfamily {
font-family: serif;
}
</style>
<script>
import prompt from '@system.prompt'
export default {
data: {
componentName: 'textarea'
},
onInit() {
this.$page.setTitleBar({ text: 'textarea' })
},
select() {
this.$element('textarea').select()
},
setSelectionRange() {
this.$element('textarea').setSelectionRange({ start: 0, end: 2 })
},
getSelectionRange() {
this.$element('textarea').getSelectionRange({
callback: function (start, end) {
prompt.showToast({
message: 'selection start:' + start + ',end:' + end
})
}
})
},
selectionchange() {
console.log('selectionchange')
},
linechange(ret) {
console.log('lineCount = ' + ret.lineCount)
console.log('height = ' + ret.height)
}
}
</script> The following figure shows the final effect.

Version | Date | Description |
|---|---|---|
1060 | - | Added the linechange event. This event is used to listen to the change of line quantity in the text area. |
1030 | 2018-10-31 |
|
1010 | 2018-04-20 |
|