TextareaItem 多行输入

用于接受多行文本。

规则

  • 支持通过键盘或者剪切板输入文本。

  • 通过光标可以在垂直或者水平方向进行移动。

代码演示

基本

受控组件建议使用(rc-form )

  1. import { List, TextareaItem } from 'antd-mobile';
  2. import { createForm } from 'rc-form';
  3. class TextareaItemExample extends React.Component {
  4. componentDidMount() {
  5. this.autoFocusInst.focus();
  6. }
  7. render() {
  8. const { getFieldProps } = this.props.form;
  9. return (
  10. <div>
  11. <List renderHeader={() => 'Customize to focus'}>
  12. <TextareaItem
  13. title="标题"
  14. placeholder="auto focus in Alipay client"
  15. data-seed="logId"
  16. ref={el => this.autoFocusInst = el}
  17. autoHeight
  18. />
  19. <TextareaItem
  20. title="标题"
  21. placeholder="click the button below to focus"
  22. data-seed="logId"
  23. autoHeight
  24. ref={el => this.customFocusInst = el}
  25. />
  26. <List.Item>
  27. <div
  28. style={{ width: '100%', color: '#108ee9', textAlign: 'center' }}
  29. onClick={() => this.customFocusInst.focus()}
  30. >
  31. click to focus
  32. </div>
  33. </List.Item>
  34. </List>
  35. <List renderHeader={() => 'Whether is controlled'}>
  36. <TextareaItem
  37. {...getFieldProps('control')}
  38. title="受控组件"
  39. placeholder="controlled"
  40. />
  41. <TextareaItem
  42. title="非受控组件"
  43. placeholder="please input content"
  44. clear
  45. />
  46. </List>
  47. <List renderHeader={() => 'Auto / Fixed height'}>
  48. <TextareaItem
  49. {...getFieldProps('note3')}
  50. title="高度自适应"
  51. autoHeight
  52. labelNumber={5}
  53. />
  54. <TextareaItem
  55. {...getFieldProps('note1')}
  56. rows={3}
  57. placeholder="fixed number of lines"
  58. />
  59. </List>
  60. <List renderHeader={() => 'Show clear'}>
  61. <TextareaItem
  62. {...getFieldProps('clear1')}
  63. clear
  64. title="标题"
  65. placeholder="displayed clear while typing"
  66. />
  67. </List>
  68. <List renderHeader={() => 'Custom title(text / image / empty)'}>
  69. <TextareaItem
  70. {...getFieldProps('title3')}
  71. title={<img src="https://gw.alipayobjects.com/zos/rmsportal/nywPmnTAvTmLusPxHPSu.png" style={{ width: '28px', height: '28px' }} alt="" />}
  72. placeholder="title can be customized"
  73. />
  74. </List>
  75. <List renderHeader={() => 'Limited value length'}>
  76. <TextareaItem
  77. {...getFieldProps('note4')}
  78. placeholder="can enter up to 10 characters"
  79. count={10}
  80. />
  81. </List>
  82. <List renderHeader={() => 'Count'}>
  83. <TextareaItem
  84. {...getFieldProps('count', {
  85. initialValue: '计数功能,我的意见是...',
  86. })}
  87. rows={5}
  88. count={100}
  89. />
  90. </List>
  91. <List renderHeader={() => 'Not editable / Disabled'}>
  92. <TextareaItem
  93. {...getFieldProps('note6', {
  94. initialValue: 'not editable',
  95. })}
  96. title="姓名"
  97. editable={false}
  98. />
  99. <TextareaItem
  100. value="disabled style"
  101. title="姓名"
  102. disabled
  103. />
  104. </List>
  105. </div>
  106. );
  107. }
  108. }
  109. const TextareaItemExampleWrapper = createForm()(TextareaItemExample);
  110. ReactDOM.render(<TextareaItemExampleWrapper />, mountNode);
  1. .demoTitle:before,
  2. .demoTitle:after {
  3. border-bottom: none;
  4. }

TextareaItem多行输入 - 图1

API

属性说明类型默认值
valuevalue 值(受控与否参考https://facebook.github.io/react/docs/forms.html)String
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
labelNumber定宽枚举值:num * @input-label-width: 34px,可用2-7之间的数字,一般(不能保证全部)能对应显示出相应个数的中文文字(不考虑英文字符)number5
nametextarea 的 nameString-
prefixListCls列表 className 前缀Stringam-list
title文案说明String/node''

TextareaItem methods

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