TextareaItem 多行输入

用于接受多行文本。

规则

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

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

代码演示

基本

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

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

TextareaItem多行输入 - 图1

API

适用平台:WEB、React-Native
属性说明类型默认值
valuevalue 值(受控与否参考https://facebook.github.io/react/docs/forms.html)String
defaultValue设置初始默认值String-
placeholderplaceholderString''
editable是否可编辑booltrue
disabled是否禁用boolfalse
clear是否带清除功能booltrue
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
name (Web Only)textarea 的 nameString-
prefixListCls (Web Only)列表 className 前缀Stringam-list
autoFocus (Web Only)页面初始化时Textarea自动获取光标,每个页面只有一个Textarea的autpFocus会生效。(不保证所有浏览器都生效)boolfalse
focused (Web Only)页面运行过程中,Textarea获取光标,当Textarea获取光标(focused更新为true)后,需要在onFocus或者onBlur时再次将该属性设置为false。boolfalse
title (Web Only)文案说明String/node''

更多属性请参考 react-native TextInput (http://facebook.github.io/react-native/docs/textinput.html)