• TextareaItem多行输入
    • 规则
  • 代码演示
  • API
  • TextareaItem methods

    TextareaItem多行输入

    用于接受多行文本。

    规则

    • 支持通过键盘或者剪切板输入文本。
    • 通过光标可以在垂直或者水平方向进行移动。

    代码演示

    基本用法

    1. import { Component } from '@angular/core';
    2. @Component({
    3. selector: 'demo-textarea-item-basic',
    4. template: `
    5. <div class="am-demo-page">
    6. <div style="padding: 15px;font-size: 16px; color:#000">Basic</div>
    7. <div class="am-list" style="margin:0;">
    8. <div class="am-list-header">Customize to focus</div>
    9. <div class="am-list-body">
    10. <TextareaItem [placeholder]="'auto focus in Alipay client'"
    11. [autoFocus]="true"
    12. [title]="'标题'"
    13. [autoHeight]="true"
    14. ></TextareaItem>
    15. <TextareaItem [placeholder]="'click the button below to focus'"
    16. [title]="'标题'"
    17. [autoHeight]="true"
    18. [focus]="inputFocus"
    19. ></TextareaItem>
    20. <div class="am-list-item am-list-item-middle">
    21. <div class="am-list-line">
    22. <div class="am-list-content" style="width:100%;color:#108ee9;text-align:center" (click)="clickFocusInput()">
    23. click to focus
    24. </div>
    25. </div>
    26. <div class="am-list-ripple" style="display: none;"></div>
    27. </div>
    28. </div>
    29. </div>
    30. <div class="am-list" style="margin:0;">
    31. <div class="am-list-header">Auto / Fixed height</div>
    32. <div class="am-list-body">
    33. <TextareaItem [title]="'高度自适应'" [autoHeight]="true" [labelNumber]="5">
    34. </TextareaItem>
    35. <TextareaItem [rows]="3" [placeholder]="'fixed number of lines'">
    36. </TextareaItem>
    37. </div>
    38. </div>
    39. <div class="am-list" style="margin:0;">
    40. <div class="am-list-header">Show clear</div>
    41. <div class="am-list-body">
    42. <TextareaItem [clear]="true" [placeholder]="'displayed clear while typing'" [title]="'标题'"></TextareaItem>
    43. </div>
    44. </div>
    45. <div class="am-list" style="margin:0;">
    46. <div class="am-list-header">Custom title(text / image / empty)</div>
    47. <div class="am-list-body">
    48. <TextareaItem [title]="customTitle" [placeholder]="'title can be customized'">
    49. </TextareaItem>
    50. </div>
    51. </div>
    52. <div class="am-list" style="margin:0;">
    53. <div class="am-list-header">Limited value length</div>
    54. <div class="am-list-body">
    55. <TextareaItem [placeholder]="'can enter up to 10 characters'" [count]="10"></TextareaItem>
    56. </div>
    57. </div>
    58. <div class="am-list" style="margin:0;">
    59. <div class="am-list-header">Count</div>
    60. <div class="am-list-body">
    61. <TextareaItem [rows]="5" [count]="100" [defaultValue]="'计数功能,我的意见是...'">手机号码</TextareaItem>
    62. </div>
    63. </div>
    64. <div class="am-list" style="margin:0;">
    65. <div class="am-list-header">Not editable / Disabled</div>
    66. <div class="am-list-body">
    67. <TextareaItem [title]="'姓名'" [editable]="false" [defaultValue]="'not editable'"></TextareaItem>
    68. <TextareaItem [title]="'姓名'" [disabled]="true" [value]="'disabled style'"></TextareaItem>
    69. </div>
    70. </div>
    71. </div>
    72. <ng-template #customTitle>
    73. <img src="https://gw.alipayobjects.com/zos/rmsportal/nywPmnTAvTmLusPxHPSu.png" style="width:28px;height:28px" alt="" />
    74. </ng-template>
    75. `,
    76. styles: [
    77. `
    78. .am-demo-page {
    79. box-sizing: content-box;
    80. }
    81. .am-list-body {
    82. position: relative;
    83. background-color: #fff;
    84. border-top: 1px solid #ddd;
    85. border-bottom: 1px solid #ddd;
    86. }
    87. .am-list-header {
    88. padding: 15px 15px 9px 15px;
    89. font-size: 14px;
    90. color: #888;
    91. width: 100%;
    92. -webkit-box-sizing: border-box;
    93. box-sizing: border-box;
    94. }
    95. /deep/ .am-list-body .am-list-item.am-textarea-item:not(:last-child) {
    96. border-bottom: 1px solid #ddd;
    97. }
    98. .am-list-item .am-list-line .am-list-content {
    99. -webkit-box-flex: 1;
    100. -webkit-flex: 1;
    101. -ms-flex: 1;
    102. flex: 1;
    103. color: #000;
    104. font-size: 17px;
    105. line-height: 1.5;
    106. text-align: left;
    107. width: auto;
    108. overflow: hidden;
    109. text-overflow: ellipsis;
    110. white-space: nowrap;
    111. padding-top: 7px;
    112. padding-bottom: 7px;
    113. }
    114. `
    115. ]
    116. })
    117. export class DemoTextareaItemBasicComponent {
    118. value;
    119. error;
    120. numberFocus = {
    121. focus: false,
    122. date: new Date()
    123. };
    124. inputFocus = {
    125. focus: false,
    126. date: new Date()
    127. };
    128. titleFocus = {
    129. focus: false,
    130. date: new Date()
    131. };
    132. autoFocus = { focus: true, date: new Date() };
    133. inputErrorClick(e) {}
    134. clickFocus() {
    135. this.numberFocus = {
    136. focus: true,
    137. date: new Date()
    138. };
    139. }
    140. clickFocusInput() {
    141. this.inputFocus = {
    142. focus: true,
    143. date: new Date()
    144. };
    145. }
    146. }

    TextareaItem多行输入 - 图1

    API

    属性说明类型默认值
    ngModelvalue, 双向绑定String
    valuevalueString
    defaultValue设置初始默认值String-
    placeholderplaceholderString''
    editable是否可编辑booltrue
    disabled是否禁用boolfalse
    clear是否带清除功能(仅editabletrue,disabledfalse才生效)boolfalse
    rows显示几行number1
    count计数功能,兼具最大长度,默认为0,代表不开启计数功能number-
    onChangechange 事件触发的回调函数(val: string): void-
    onBlurblur 事件触发的回调函数(val: string): void-
    onFocusfocus 事件触发的回调函数(val: string): void-
    error报错样式boolfalse
    onErrorClick点击报错 icon 触发的回调(): void
    autoHeight高度自适应, autoHeight 和 rows 请二选一boolfalse
    autoFocus初始化自动获得焦点boolfalse
    labelNumber定宽枚举值:num * @input-label-width: 34px,可用2-7之间的数字,一般(不能保证全部)能对应显示出相应个数的中文文字(不考虑英文字符)number5
    nametextarea 的 nameString-
    prefixListCls列表 className 前缀Stringam-list
    title文案说明String/node''

    TextareaItem methods

    属性说明类型默认值
    focus强制获得焦点--