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

TextareaItem多行输入 - 图1

API

参数说明类型默认值
[value]valuestring-
[defaultValue]设置初始默认值string-
[placeholder]placeholderstring-
[editable]是否可编辑booleantrue
[disabled]是否禁用booleanfalse
[clear]是否带清除功能(仅editabletrue,disabledfalse才生效)booleanfalse
[rows]显示几行number1
[count]计数功能,兼具最大长度,默认为0,代表不开启计数功能number-
[error]报错样式booleanfalse
[autoHeight]高度自适应, autoHeight 和 rows 请二选一booleanfalse
[autoFocus]初始化自动获得焦点booleanfalse
[labelNumber]定宽枚举值:num * @input-label-width: 34px,可用2-7之间的数字,一般(不能保证全部)能对应显示出相应个数的中文文字(不考虑英文字符)number5
[name]textarea 的 namestring-
[prefixListCls]列表 className 前缀string‘am-list’
[title]文案说明string | TemplateRef-
[focus]强制获得焦点{ focus: boolean }-
[(ngModel)]valuestring-
(onChange)change 事件触发的回调函数EventEmitter<string>-
(onBlur)blur 事件触发的回调函数EventEmitter<string>-
(onFocus)focus 事件触发的回调函数EventEmitter<string>-
(onErrorClick)点击报错 icon 触发的回调EventEmitter<void>-